At backend I have created a nice Exception mechanism so when a request fail. Server going to send a nice error message to client with some error code .
Like this:
@Getter
public class ErrorResponse {
/**
* Http Response status code
*/
private final HttpStatus status;
/**
* General Error Message
*/
private final String message;
private final ErrorCode errorCode;
private final Date timeStamp;
...
}
I want to show error messages to user by default for each fail.
I have tried to extend HttpClient
public get<T>(endPoint: string, options?: IRequestOptions): Observable<T> {
return this.http.get<T>(this.API + endPoint, options);
}
But it's returning an Observable
In most of page I am doing something like this.:
this.client.post(WebUtils.RESOURCE_HOST + '/api' + '/actor/create', formData
).subscribe(
() => this.onSuccessfulPost(),
error => {
this.snack.error(error.error.message);
}
);
In a lot of pages I am writing the same thing :
error => {
this.snack.error(error.error.message);
}
I read this post which about extending HttpClient.
But it is not enough for me it's only defining a default "API_HOST" I want to define default error function for request methods return objects and they are Observables.
Is there anyway to manipulate returning object of "HttpClient Request Methods" like extending?