strong-error-handler/lib/send-json.js

15 lines
463 B
JavaScript

// Copyright IBM Corp. 2016. All Rights Reserved.
// Node module: strong-error-handler
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
var safeStringify = require('fast-safe-stringify');
module.exports = function sendJson(res, data) {
var content = safeStringify({error: data});
res.setHeader('Content-Type', 'application/json; charset=utf-8');
res.end(content, 'utf-8');
};