Skip to content

Commit 326ba5f

Browse files
author
Oliver Rumbelow
committed
Merge pull request #146 from holidayextras/error-on-broken-resource
Error when interacting with broken resources
2 parents 95a5d28 + bdf21fc commit 326ba5f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/routes/find.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ findRoute.register = function() {
3636
responseHelper._enforceSchemaOnObject(resource, resourceConfig.attributes, callback);
3737
},
3838
function(sanitisedData, callback) {
39+
if (!sanitisedData) {
40+
return callback({
41+
status: "404",
42+
code: "EVERSION",
43+
title: "Resource is not valid",
44+
detail: "The requested resource does not conform to the API specification. This is usually the result of a versioning change."
45+
});
46+
}
3947
response = responseHelper._generateResponse(request, resourceConfig, sanitisedData);
4048
response.included = [ ];
4149
postProcess.handle(request, response, callback);

lib/routes/relationships.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ relationshipsRoute.register = function() {
4444
responseHelper._enforceSchemaOnObject(resource, resourceConfig.attributes, callback);
4545
},
4646
function(sanitisedData, callback) {
47+
if (!sanitisedData) {
48+
return callback({
49+
status: "404",
50+
code: "EVERSION",
51+
title: "Resource is not valid",
52+
detail: "The requested resource does not conform to the API specification. This is usually the result of a versioning change."
53+
});
54+
}
4755
sanitisedData = sanitisedData.relationships[request.params.relation].data;
4856
response = responseHelper._generateResponse(request, resourceConfig, sanitisedData);
4957
callback();

0 commit comments

Comments
 (0)