Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use API strategy for txt format to get correct statusCode in response

  • Loading branch information...
commit d6b0bd771e1181ecdbca910f99fbe17db01379c1 1 parent 03c9171
@mde mde authored
View
1  lib/controller/responder/index.js
@@ -18,6 +18,7 @@ responder.strategies = {
html: htmlStrategy
, json: apiStrategy
, xml: apiStrategy
+, txt: apiStrategy
};
responder.Responder = function () {
View
11 lib/controller/responder/strategies/api.js
@@ -60,7 +60,18 @@ var utils = require('utilities')
, message: content.message
, stack: content.stack
};
+
+ // Transfer the statusCode from the Error object to the
+ // options, to be spit out in the response
options.statusCode = content.statusCode || 500;
+
+ // Plaintext needs a reasonable way to get a string other
+ // than stupid [Object object]
+ if (options.format == 'txt') {
+ response.toString = function () {
+ return this.message;
+ };
+ }
}
else {
throw new Error(
Please sign in to comment.
Something went wrong with that request. Please try again.