Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few more store -> core dependency fixes #4383

Merged
merged 13 commits into from
Jun 23, 2020
3 changes: 1 addition & 2 deletions src/frontend/packages/cloud-foundry/src/cf-error-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { jetStreamErrorResponseToSafeString } from '../../core/src/jetstream.helpers';
import { JetStreamErrorResponse } from '../../store/src/jetstream';
import { JetStreamErrorResponse, jetStreamErrorResponseToSafeString } from '../../store/src/jetstream';

export interface CfErrorObject {
code: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { filter, first, map } from 'rxjs/operators';
import { GetAllEndpoints } from '../../../../../../store/src/actions/endpoint.actions';
import { AppState } from '../../../../../../store/src/app-state';
import { entityCatalog } from '../../../../../../store/src/entity-catalog/entity-catalog';
import { httpErrorResponseToSafeString } from '../../../../../../store/src/jetstream';
import { PaginationMonitorFactory } from '../../../../../../store/src/monitors/pagination-monitor.factory';
import { getPaginationObservables } from '../../../../../../store/src/reducers/pagination-reducer/pagination-reducer.helper';
import { EndpointModel } from '../../../../../../store/src/types/endpoint.types';
import { httpErrorResponseToSafeString } from '../../../../jetstream.helpers';
import { ConfirmationDialogConfig } from '../../../../shared/components/confirmation-dialog.config';
import { ConfirmationDialogService } from '../../../../shared/components/confirmation-dialog.service';
import { ITableListDataSource } from '../../../../shared/components/list/data-sources-controllers/list-data-source-types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { first, map } from 'rxjs/operators';

import { GetAllEndpoints } from '../../../../../../store/src/actions/endpoint.actions';
import { GeneralEntityAppState } from '../../../../../../store/src/app-state';
import { httpErrorResponseToSafeString } from '../../../../../../store/src/jetstream';
import { getEventFiles } from '../../../../core/browser-helper';
import { httpErrorResponseToSafeString } from '../../../../jetstream.helpers';
import { ConfirmationDialogConfig } from '../../../../shared/components/confirmation-dialog.config';
import { ConfirmationDialogService } from '../../../../shared/components/confirmation-dialog.service';
import { StepOnNextFunction, StepOnNextResult } from '../../../../shared/components/stepper/step/step.component';
Expand Down
24 changes: 0 additions & 24 deletions src/frontend/packages/core/src/jetstream.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,3 @@ import { HttpErrorResponse } from '@angular/common/http';

import { isHttpErrorResponse, JetStreamErrorResponse } from '../../store/src/jetstream';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file can be nuked in a future PR



export function jetStreamErrorResponseToSafeString(response: JetStreamErrorResponse): string {
return response.error && response.error.status && response.error.statusCode ?
`${response.error.status}. Status Code ${response.error.statusCode}` :
null;
}

/**
* Attempt to create a sensible string explaining the error object returned from a failed http request
* @param err The raw error from a http request
*/
export function httpErrorResponseToSafeString(err: any): string {
const httpResponse: HttpErrorResponse = isHttpErrorResponse(err);
if (httpResponse) {
if (httpResponse.error) {
if (typeof (httpResponse.error) === 'string') {
return httpResponse.error + ` (${httpResponse.status})`;
}
return httpResponse.error.error + ` (${httpResponse.status})`;
}
return JSON.stringify(httpResponse.error) + ` (${httpResponse.status})`;
}
return err.message;
}
24 changes: 24 additions & 0 deletions src/frontend/packages/store/src/jetstream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,30 @@ export function isHttpErrorResponse(obj: any): HttpErrorResponse {
) ? obj as HttpErrorResponse : null;
}

export function jetStreamErrorResponseToSafeString(response: JetStreamErrorResponse): string {
return response.error && response.error.status && response.error.statusCode ?
`${response.error.status}. Status Code ${response.error.statusCode}` :
null;
}

/**
* Attempt to create a sensible string explaining the error object returned from a failed http request
* @param err The raw error from a http request
*/
export function httpErrorResponseToSafeString(err: any): string {
const httpResponse: HttpErrorResponse = isHttpErrorResponse(err);
if (httpResponse) {
if (httpResponse.error) {
if (typeof (httpResponse.error) === 'string') {
return httpResponse.error + ` (${httpResponse.status})`;
}
return httpResponse.error.error + ` (${httpResponse.status})`;
}
return JSON.stringify(httpResponse.error) + ` (${httpResponse.status})`;
}
return err.message;
}

// TODO It would be nice if the BE could return a unique para for us to check for. #3827
// There is always a chance that this will return a false positive (more so with extensions).
export function hasJetStreamError(pages: Partial<JetStreamErrorResponse>[]): JetStreamErrorResponse {
Expand Down