Skip to content

Instantly share code, notes, and snippets.

@melcor76
Last active Jan 24, 2019
Embed
What would you like to do?
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