Created
May 9, 2017 11:59
-
-
Save vespertilian/228ba0ba6805a6ba3b26f3a757b07438 to your computer and use it in GitHub Desktop.
Handling angular errors
This file contains hidden or 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 { 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