Last active
September 1, 2017 07:53
AngularJS logging with date information
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
@Injectable() | |
export class ErrorLogService { | |
private name: String = 'ErrorLogService'; | |
constructor() { | |
} | |
logError(error: any) { | |
const date = new Date().toISOString(); | |
if (error instanceof HttpErrorResponse) { | |
console.error(date, 'There was an HTTP error.', error.message, 'Status code:', (<HttpErrorResponse>error).status); | |
} else if (error instanceof TypeError) { | |
console.error(date, 'There was a Type error.', error.message); | |
} else if (error instanceof Error) { | |
console.error(date, 'There was a general error.', error.message); | |
} else { | |
console.error(date, 'Nobody threw an Error but something happened!', error); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment