We have a component that handles view management and a service that manages server interaction and data parsing.
The service postForm method returns a shared observable to the component. The service subscribes to it and the component does.
On success, the service callback method does some data stuff Also on success or error the component callback updates feedback in the view.
Problem: The component error callback only fires if the service subscribe function includes an error callback.
Am I using a bad pattern? If not why do I need error callbacks in both subscribe functions to get the component one to work?
Thanks
Component:
onSubmit(): void {
this.service.postForm().subscribe(
() => this.onSuccessfulPost(),
()=>this.onErrorPost()
);
}
Service:
postForm() {
//Code here assembles url and body variables
this.currentObservable = this.http.post(url, body)
.map((response: Response) => this.parseResponse(response))
.catch((err: Response) => this.onHttpError(err)).share();
this.currentObservable.subscribe(
(response: any) => this.onSuccessfulPost(response),
() => {return} //WITHOUT THIS LINE COMPONENT CALL FAILS
);
return this.currentObservable;
}