Three functions are responsible for triggering POST API calls, with the intention of returning a success or failure message to whoever invokes them (Observable<string>
).
In an effort to avoid repetition, I introduced a new function to retrieve success messages. However, this new implementation seems to be causing issues as when I call getSuccessMessage
, the app displays a blank page. Interestingly, using a regular string ("Something") in its place works as expected.
Here are the functions in question:
export enum ListType {Cars, Animals, Books}
public updateOne(carList: Car[]): Observable<string> {
return this._myApiSevice.postCarsNewOrder(carList)
.map(response => this.getSuccessMessage(ListType.Cars)) //update succeeded
.catch(error => Observable.of("FAILURE: post to Cars did not succeed!"));
}
public updateTwo(animalList: Animal[]): Observable<string> {
return this._myApiSevice.postAnimalsNewOrder(animalList)
.map(response => this.getSuccessMessage(ListType.Animals))
.catch(error => Observable.of("FAILURE: post to Animals did not succeed!"));
}
public updateThree(bookList: Book[]): Observable<string> {
return this._myApiSevice.postBooksNewOrder(bookList)
.map(response => this.getSuccessMessage(ListType.Books)) //update succeeded
.catch(error => Observable.of("FAILURE: post to Books did not succeed!"));
}
public getSuccessMessage(listType: ListType): string {
return "SUCCESS: post to " + ListType[listType] + "succeed!";
}
Do you notice anything wrong here?
This error is displayed in the console:
EXCEPTION: Error: Uncaught (in promise): Cannot resolve all parameters for 'MyCmp'(undefined, ElementRef, MdDialog). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'MyCmp' is decorated with Injectable.
The enum is declared in another class which is imported to access the enums.
If you have any suggestions on how to consolidate the failure message logic along with the success message into one function, I would greatly appreciate it. Thank you!