Skip to content

Commit 2e3f35e

Browse files
committed
Do not try to interpret errors in res.negociate
1 parent 60d8080 commit 2e3f35e

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

lib/api/responses/negotiate.js

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,18 @@
2020

2121
module.exports = function negotiate (err) {
2222

23-
// Get access to response object (`res`)
2423
var res = this.res;
24+
var statusCode = err.status || 500;
2525

26-
var statusCode = 500;
27-
var body = err;
28-
29-
try {
30-
31-
statusCode = err.status || 500;
32-
33-
// Set the status
34-
// (should be taken care of by res.* methods, but this sets a default just in case)
35-
res.status(statusCode);
36-
37-
} catch (e) {}
26+
res.status(statusCode);
3827

3928
// Respond using the appropriate custom response
40-
if (statusCode === 403) return res.forbidden(body);
41-
if (statusCode === 404) return res.notFound(body);
29+
if (statusCode === 403) return res.forbidden(err);
30+
if (statusCode === 404) return res.notFound(err);
4231

43-
console.log(body);
4432
// This check is specific to sails-json-api-blueprints
45-
if (statusCode === 400 && err.code === "E_VALIDATION") return res.invalid(body);
33+
if (statusCode === 400 && err.code === "E_VALIDATION") return res.invalid(err);
34+
if (statusCode === 400) return res.badRequest(err);
4635

47-
if (statusCode >= 400 && statusCode < 500) return res.badRequest(body);
48-
return res.serverError(body);
36+
return res.json(err);
4937
};

0 commit comments

Comments
 (0)