Skip to content

Instantly share code, notes, and snippets.

@vespertilian
Created May 9, 2017 11:59
Show Gist options
  • Save vespertilian/228ba0ba6805a6ba3b26f3a757b07438 to your computer and use it in GitHub Desktop.
Save vespertilian/228ba0ba6805a6ba3b26f3a757b07438 to your computer and use it in GitHub Desktop.
Handling angular errors
import { Response, ResponseOptions } from '@angular/http';
class ErrorResponse extends Response implements Error {
name: any;
message: any;
}
export function mockError(errorResponseOpts: any) {
return new ErrorResponse(new ResponseOptions(errorResponseOpts));
};
const response = mockError({
body: {
'message': 'No Such Object'
},
status: 404
});
// you can now use this in a service to mock an error message
return Observable.throw(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment