Skip to content

Commit

Permalink
feat: use ishServerHtml for header error-keys in error-message component
Browse files Browse the repository at this point in the history
  • Loading branch information
shauke committed Feb 20, 2020
1 parent 8716834 commit 2e87448
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@
{{ error.statusText }}: {{ error.error.errorMessage }} <br />{{ error.error.failures }}
</ng-container>
<ng-template #generalError>
<!-- handle HttpErrorResponse with error keys in the response header (old style) -->
<ng-container *ngIf="error.headers && error.headers['error-key']">
<span [ishServerHtml]="error.headers['error-key'] | translate"></span>
</ng-container>
<!-- handle HttpErrorResponse with JSON error response and no error keys (new style) -->
<ng-container *ngIf="!(error.headers && error.headers['error-key']) && error.error">
{{ error.error }}
</ng-container>
<!-- handle HttpErrorResponse with no error keys and no error response (fallback) -->
<ng-container *ngIf="!(error.headers && error.headers['error-key']) && !error.error">
{{ error.status }}: {{ error.message }}
</ng-container>
{{ (error.headers && error.headers['error-key'] | translate) || error.error }}
</ng-template>
<ng-content></ng-content>
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { MockDirective } from 'ng-mocks';

import { ServerHtmlDirective } from 'ish-core/directives/server-html.directive';
import { HttpError } from 'ish-core/models/http-error/http-error.model';

import { ErrorMessageComponent } from './error-message.component';
Expand All @@ -13,7 +15,7 @@ describe('Error Message Component', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot()],
declarations: [ErrorMessageComponent],
declarations: [ErrorMessageComponent, MockDirective(ServerHtmlDirective)],
}).compileComponents();
}));

Expand Down

0 comments on commit 2e87448

Please sign in to comment.