Skip to content

Instantly share code, notes, and snippets.

@melcor76
Last active January 24, 2019 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melcor76/45fd898d664bd59dc22304247f4a8108 to your computer and use it in GitHub Desktop.
Save melcor76/45fd898d664bd59dc22304247f4a8108 to your computer and use it in GitHub Desktop.
Error handling - error.service.ts
import { Injectable } from '@angular/core';
import { HttpErrorResponse } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class ErrorService {
getClientMessage(error: Error): string {
if (!navigator.onLine) {
return 'No Internet Connection';
}
return error.message ? error.message : error.toString();
}
getClientStack(error: Error): string {
return error.stack;
}
getServerMessage(error: HttpErrorResponse): string {
return error.message;
}
getServerStack(error: HttpErrorResponse): string {
// handle stack trace
return 'stack';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment