Browse Source

Fix proxy error handling for 502/503/504 HTTP status codes

Move 504 handling from interceptor to parseHttpErrorMessage, add
user-friendly messages for 502/503/504 via httpStatusMessageMap,
and scope isProxyError to only match proxy status codes to avoid
breaking error handling for other HTTP errors.
pull/15305/head
Vladyslav Prykhodko 2 months ago
committed by Vladyslav Prykhodko
parent
commit
00e35f745e
  1. 4
      ui-ngx/src/app/core/interceptors/global-http-interceptor.ts
  2. 18
      ui-ngx/src/app/core/utils.ts
  3. 6
      ui-ngx/src/app/shared/models/constants.ts

4
ui-ngx/src/app/core/interceptors/global-http-interceptor.ts

@ -125,10 +125,6 @@ export class GlobalHttpInterceptor implements HttpInterceptor {
this.showError(req.method + ': ' + req.url + '<br/>' +
errorResponse.status + ': ' + errorResponse.statusText);
}
} else if (errorResponse.status === 504) {
if (!ignoreErrors) {
this.showError('Request timeout');
}
} else {
unhandled = true;
}

18
ui-ngx/src/app/core/utils.ts

@ -23,7 +23,7 @@ import { NULL_UUID } from '@shared/models/id/has-uuid';
import { baseDetailsPageByEntityType, EntityType } from '@shared/models/entity-type.models';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { TranslateService } from '@ngx-translate/core';
import { serverErrorCodesTranslations } from '@shared/models/constants';
import { httpStatusMessageMap, serverErrorCodesTranslations } from '@shared/models/constants';
import { SubscriptionEntityInfo } from '@core/api/widget-api.models';
import {
CompiledTbFunction,
@ -825,11 +825,13 @@ export function parseHttpErrorMessage(errorResponse: HttpErrorResponse,
} else {
error = errorResponse.error;
}
if (error && !error.message) {
errorMessage = prepareMessageFromData(error);
} else if (error && error.message) {
if (error && error.message) {
errorMessage = error.message;
timeout = error.timeout ? error.timeout : 0;
} else if (isProxyError(errorResponse)) {
errorMessage = httpStatusMessageMap.get(errorResponse.status);
} else if (error) {
errorMessage = prepareMessageFromData(error);
} else {
errorMessage = `Unhandled error code ${error ? error.status : '\'Unknown\''}`;
}
@ -866,6 +868,14 @@ function prepareMessageFromData(data): string {
}
}
function isProxyError(errorResponse: HttpErrorResponse): boolean {
if (!httpStatusMessageMap.has(errorResponse.status)) {
return false;
}
const error = errorResponse.error;
return !error || typeof error === 'string' || (typeof error === 'object' && !error.message);
}
export const genNextLabel = (name: string, datasources: Datasource[]): string => {
let label = name;
let i = 1;

6
ui-ngx/src/app/shared/models/constants.ts

@ -54,6 +54,12 @@ export const serverErrorCodesTranslations = new Map<number, string>([
[Constants.serverErrorCode.tooManyUpdates, 'server-error.too-many-updates'],
]);
export const httpStatusMessageMap = new Map<number, string>([
[502, 'Server is temporarily unavailable (Bad Gateway)'],
[503, 'Server is temporarily unavailable'],
[504, 'Server did not respond in time (Gateway Timeout)'],
]);
export const MediaBreakpoints = {
xs: 'screen and (max-width: 599px)',
sm: 'screen and (min-width: 600px) and (max-width: 959px)',

Loading…
Cancel
Save