Skip to content

Commit

Permalink
Improve ng2 error handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
Schinkentanz committed Aug 10, 2020
1 parent 1d42cfc commit 0e05fb6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/angular2/shared/services/core/error.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import { Observable, throwError } from 'rxjs';
@Injectable()
export class ErrorHandler {
public handleError(errorResponse: HttpErrorResponse): Observable<never> {
return throwError(errorResponse.error.error || 'Server error');
if (errorResponse instanceof Error) {
return throwError(errorResponse);
}

const error = errorResponse?.error?.error;
const errorMessage = error?.message || error?.stack || error || 'Unknown error occured';

return throwError(new Error(errorMessage));
}
}

0 comments on commit 0e05fb6

Please sign in to comment.