Skip to content

Instantly share code, notes, and snippets.

@mrister
Last active September 1, 2017 07:53
Show Gist options
  • Save mrister/620834a0d414eb1292c531894994b2cc to your computer and use it in GitHub Desktop.
Save mrister/620834a0d414eb1292c531894994b2cc to your computer and use it in GitHub Desktop.
AngularJS logging with date information
@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