amphora-rss
Advanced tools
Comparing version 0.3.0 to 0.4.0
18
index.js
@@ -91,2 +91,13 @@ 'use strict'; | ||
function sendError(res, e, message) { | ||
var message = message || e.message; | ||
res.status(500); | ||
res.json({ status: 500, message }); | ||
log('error', e.message, { | ||
stack: e.stack | ||
}); | ||
} | ||
/** | ||
@@ -106,5 +117,3 @@ * Given the data object from Amphora, make the XML | ||
.map(wrapInTopLevel) | ||
.errors(error => { | ||
log('error', error.message); | ||
}) | ||
.errors(e => sendError(res, e)) | ||
.toPromise(Promise) | ||
@@ -118,3 +127,4 @@ .then(data => { | ||
res.send(xml(data, { declaration: true, indent: '\t' })); | ||
}); | ||
}) | ||
.catch(e => sendError(res, e)); | ||
}; | ||
@@ -121,0 +131,0 @@ |
@@ -23,2 +23,11 @@ 'use strict'; | ||
function makeFakeRes() { | ||
return { | ||
type: sandbox.spy(), | ||
send: sandbox.spy(), | ||
status: sandbox.spy(), | ||
json: sandbox.spy() | ||
}; | ||
} | ||
describe('render', function () { | ||
@@ -48,9 +57,11 @@ const fn = lib[this.title]; | ||
it('works', function () { | ||
const result = fn({ | ||
feed: [], | ||
meta: {} | ||
}); | ||
const res = makeFakeRes(), | ||
result = fn({ | ||
feed: [], | ||
meta: {} | ||
}, {}, res); | ||
result.catch(function (err) { | ||
sinon.assert.match(err.message, /No data send to XML renderer, cannot respond/); | ||
result.then(function () { | ||
sinon.assert.calledWith(res.json, {status: 500, message: 'No data send to XML renderer, cannot respond'}); | ||
}); | ||
@@ -57,0 +68,0 @@ }); |
{ | ||
"name": "amphora-rss", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Convert JSON from Amphora into RSS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
16516
308