September 2017
Intermediate to advanced
450 pages
11h 24m
English
Another useful feature built into jsonapi-serializer is providing JSON API-formatted error responses. We can update our /middleware/rest.js middleware to provide 404 error responses in our REST API that are formatted consistently to align with the JSON API specification.
...var JSONAPIError = require('jsonapi-serializer').Error;module.exports = function(resourceId, store, serialize, deserialize) { var serializer = new JSONAPISerializer(resourceId, serialize); var deserializer = new JSONAPIDeserializer(deserialize); var error = function(status, title, description) { return new JSONAPIError({ status: status, title: title, detail: description }); }; var fileNotFound = function() { return error(404, 'Not found', 'Resource does ...
Read now
Unlock full access