If a client sends a POST request with a LicenseNumber that already exists in the database (and must be unique), the server will respond as follows:
{"errorCode":"Validation Error",
"errorMessage":"Invalid inputs.",
"errors":["Such license number already exists"]}
How can I display the "errors" message in my view?
I attempted to do so with the following method:
update(doctor: Doctor): Promise<Doctor> {
const url =`${this.doctorsUrl}/${doctor.id}`;
return this.http.put(url, JSON.stringify(doctor), {headers: this.headers})
.toPromise()
.then(() => doctor)
.catch(this.handleError);
}
private handleError(errors: any): Promise<any> {
console.error('An error occurred', errors);
return Promise.reject(errors.message || errors);
}
However, when I send a test bad request in the console, I only get a regular 400 BAD_REQUEST ERR.
Any suggestions on how I can catch this specific error?
Thank you, Bartek