Browse Source

create HTTP_ERROR_HANDLER injection token

pull/7960/head
mehmet-erim 6 years ago
parent
commit
fe5399026f
  1. 9
      npm/ng-packs/packages/theme-shared/src/lib/models/common.ts
  2. 6
      npm/ng-packs/packages/theme-shared/src/lib/tokens/http-error.token.ts

9
npm/ng-packs/packages/theme-shared/src/lib/models/common.ts

@ -1,5 +1,7 @@
import { Type } from '@angular/core'; import { HttpErrorResponse } from '@angular/common/http';
import { Injector, Type } from '@angular/core';
import { Validation } from '@ngx-validate/core'; import { Validation } from '@ngx-validate/core';
import { Observable } from 'rxjs';
export interface RootParams { export interface RootParams {
httpErrorConfig: HttpErrorConfig; httpErrorConfig: HttpErrorConfig;
@ -17,4 +19,9 @@ export interface HttpErrorConfig {
}; };
} }
export type HttpErrorHandler = (
injector: Injector,
httpError: HttpErrorResponse,
) => Observable<any>;
export type LocaleDirection = 'ltr' | 'rtl'; export type LocaleDirection = 'ltr' | 'rtl';

6
npm/ng-packs/packages/theme-shared/src/lib/tokens/http-error.token.ts

@ -1,5 +1,5 @@
import { InjectionToken } from '@angular/core'; import { InjectionToken } from '@angular/core';
import { HttpErrorConfig } from '../models/common'; import { HttpErrorConfig, HttpErrorHandler } from '../models/common';
export function httpErrorConfigFactory(config = {} as HttpErrorConfig) { export function httpErrorConfigFactory(config = {} as HttpErrorConfig) {
if (config.errorScreen && config.errorScreen.component && !config.errorScreen.forWhichErrors) { if (config.errorScreen && config.errorScreen.component && !config.errorScreen.forWhichErrors) {
@ -13,4 +13,6 @@ export function httpErrorConfigFactory(config = {} as HttpErrorConfig) {
} as HttpErrorConfig; } as HttpErrorConfig;
} }
export const HTTP_ERROR_CONFIG = new InjectionToken('HTTP_ERROR_CONFIG'); export const HTTP_ERROR_CONFIG = new InjectionToken<HttpErrorConfig>('HTTP_ERROR_CONFIG');
export const HTTP_ERROR_HANDLER = new InjectionToken<HttpErrorHandler>('HTTP_ERROR_HANDLER');

Loading…
Cancel
Save