In D8 i’m trying to throw custom exceptions for extra validations that i need to do before the content is saved in my custom entity, but when i do the validations in the presave method and throw a normal Exception:
public function preSave(EntityStorageInterface $storage) { throw new Exception("The content is duplicated", 409); }
The response of JSONAPI is code 500 Internal Server Error and the response:
{ "jsonapi": { "version": "1.0", "meta": { "links": { "self": { "href": "http://jsonapi.org/format/1.0/" } } } }, "errors": [ { "title": "Internal Server Error", "status": "500", "detail": "The content is duplicated", "links": { "via": { "href": "http://site.docksal/jsonapi/content_entity/content_entity" }, "info": { "href": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.1" } } } ]
}
how can i control de error Code, title, status and detail.