Setting up a service using aurelia-fetch-client I have the following method:
public CreateEntity() : Promise<Entity>{
return this.httpClient.fetch(route)
.then(response => {
if(response.ok && response.status == 200) return response.json();
})
.catch(err => {
throw new Error("oh no. Something went wrong")
})
}
Now the point is, that the API also returns validation-errors with status code of 400 and references to each invalid field.
How can I interpret the 400 error message?
In my form I currently only get the object:
this.myService.CreateEntity().then(Entity => {
this.entity = Entity;
})
Update:
In beset case I would like to parse the error Response and work with aurelia-validation “addError”. Does anyone have an example?