Name: js-handler/node_modules/restify/lib/formatters/text.js
| 1: | // Copyright 2012 Mark Cavage, Inc. All rights reserved. |
| 2: | |
| 3: | |
| 4: | |
| 5: | ///--- Exports |
| 6: | |
| 7: | function formatText(req, res, body) { |
| 8: | if (body instanceof Error) { |
| 9: | res.statusCode = body.statusCode || 500; |
| 10: | body = body.message; |
| 11: | } else if (typeof (body) === 'object') { |
| 12: | body = JSON.stringify(body); |
| 13: | } else { |
| 14: | body = body.toString(); |
| 15: | } |
| 16: | |
| 17: | res.setHeader('Content-Length', Buffer.byteLength(body)); |
| 18: | return (body); |
| 19: | } |
| 20: | |
| 21: | module.exports = formatText; |
