Browse Source

feat: add default error localizations to error.handler

pull/5124/head
mehmet-erim 6 years ago
parent
commit
90a1f9bd18
  1. 48
      npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts

48
npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts

@ -43,6 +43,29 @@ export const DEFAULT_ERROR_MESSAGES = {
}, },
}; };
export const DEFAULT_ERROR_LOCALIZATIONS = {
defaultError: {
title: 'AbpUi::DefaultErrorMessage',
details: 'AbpUi::DefaultErrorMessageDetail',
},
defaultError401: {
title: 'AbpUi::DefaultErrorMessage401',
details: 'AbpUi::DefaultErrorMessage401Detail',
},
defaultError403: {
title: 'AbpUi::DefaultErrorMessage403',
details: 'AbpUi::DefaultErrorMessage403Detail',
},
defaultError404: {
title: 'AbpUi::DefaultErrorMessage404',
details: 'AbpUi::DefaultErrorMessage404Detail',
},
defaultError500: {
title: 'AbpUi::500Message',
details: 'AbpUi::DefaultErrorMessage',
},
};
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class ErrorHandler { export class ErrorHandler {
componentRef: ComponentRef<HttpErrorWrapperComponent>; componentRef: ComponentRef<HttpErrorWrapperComponent>;
@ -88,7 +111,10 @@ export class ErrorHandler {
filter(this.filterRestErrors), filter(this.filterRestErrors),
) )
.subscribe(err => { .subscribe(err => {
const body = snq(() => err.error.error, DEFAULT_ERROR_MESSAGES.defaultError.title); const body = snq(() => err.error.error, {
key: DEFAULT_ERROR_LOCALIZATIONS.defaultError.title,
defaultValue: DEFAULT_ERROR_MESSAGES.defaultError.title,
});
if (err instanceof HttpErrorResponse && err.headers.get('_AbpErrorFormat')) { if (err instanceof HttpErrorResponse && err.headers.get('_AbpErrorFormat')) {
const confirmation$ = this.showError(null, null, body); const confirmation$ = this.showError(null, null, body);
@ -168,8 +194,14 @@ export class ErrorHandler {
break; break;
default: default:
this.showError( this.showError(
DEFAULT_ERROR_MESSAGES.defaultError.details, {
DEFAULT_ERROR_MESSAGES.defaultError.title, key: DEFAULT_ERROR_LOCALIZATIONS.defaultError.details,
defaultValue: DEFAULT_ERROR_MESSAGES.defaultError.details,
},
{
key: DEFAULT_ERROR_LOCALIZATIONS.defaultError.title,
defaultValue: DEFAULT_ERROR_MESSAGES.defaultError.title,
},
); );
break; break;
} }
@ -207,10 +239,16 @@ export class ErrorHandler {
message = body.details; message = body.details;
title = body.message; title = body.message;
} else if (body.message) { } else if (body.message) {
title = DEFAULT_ERROR_MESSAGES.defaultError.title; title = {
key: DEFAULT_ERROR_LOCALIZATIONS.defaultError.title,
defaultValue: DEFAULT_ERROR_MESSAGES.defaultError.title,
};
message = body.message; message = body.message;
} else { } else {
message = body.message || DEFAULT_ERROR_MESSAGES.defaultError.title; message = body.message || {
key: DEFAULT_ERROR_LOCALIZATIONS.defaultError.title,
defaultValue: DEFAULT_ERROR_MESSAGES.defaultError.title,
};
} }
} }

Loading…
Cancel
Save