-
-
Save melcor76/45fd898d664bd59dc22304247f4a8108 to your computer and use it in GitHub Desktop.
Error handling - error.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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