- unexpected
- server offline
- unhandled exceptions
- network is down
- expected
- 400 - Bad Request
- 404 - Not Found
Make sure you handle those types accordingly(by status code checks, etc.)
Make sure you've already set up a service for dealing with data.
Use the catch
operator to return new observable which contains the error
...
Obervable.throw(...{type of error})
...
type of error - specific to our application domain
which means, create new class which represents app specific errors
class AppError {
constructor(public originalError?: any) {}
}
Create specific app domain errors which inherit from the general app error
class NotFoundError extends AppError {}
Service level - check the status and return new Observable based on the type of app domain error
Component level - check if the error is an instance of specific type of app domain class error and act accordingly
Angular does provide global error handler