Skip to content

Commit

Permalink
Merge pull request #146 from holidayextras/error-on-broken-resource
Browse files Browse the repository at this point in the history
Error when interacting with broken resources
  • Loading branch information
theninj4 committed Jun 2, 2016
2 parents 95a5d28 + bdf21fc commit 326ba5f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/routes/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ findRoute.register = function() {
responseHelper._enforceSchemaOnObject(resource, resourceConfig.attributes, callback);
},
function(sanitisedData, callback) {
if (!sanitisedData) {
return callback({
status: "404",
code: "EVERSION",
title: "Resource is not valid",
detail: "The requested resource does not conform to the API specification. This is usually the result of a versioning change."
});
}
response = responseHelper._generateResponse(request, resourceConfig, sanitisedData);
response.included = [ ];
postProcess.handle(request, response, callback);
Expand Down
8 changes: 8 additions & 0 deletions lib/routes/relationships.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ relationshipsRoute.register = function() {
responseHelper._enforceSchemaOnObject(resource, resourceConfig.attributes, callback);
},
function(sanitisedData, callback) {
if (!sanitisedData) {
return callback({
status: "404",
code: "EVERSION",
title: "Resource is not valid",
detail: "The requested resource does not conform to the API specification. This is usually the result of a versioning change."
});
}
sanitisedData = sanitisedData.relationships[request.params.relation].data;
response = responseHelper._generateResponse(request, resourceConfig, sanitisedData);
callback();
Expand Down

0 comments on commit 326ba5f

Please sign in to comment.