From 20555daf07d828f9f847cd1c76f114acb92228f1 Mon Sep 17 00:00:00 2001 From: Joannic Laborde Date: Thu, 27 Oct 2016 17:14:20 -0300 Subject: [PATCH] Return 500 instead of status error --- lib/page.js | 2 +- test/solidus.js | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/page.js b/lib/page.js index b1e542c..61fe9d9 100644 --- a/lib/page.js +++ b/lib/page.js @@ -178,7 +178,7 @@ var Page = function( page_path, options ){ async.each( resources_array, function( resource, cb ){ resource.get(function(err, resource_response) { if (err) { - var status = err.status || 500; + var status = err.status == 404 ? 404 : 500; var error = 'Resource error: ' + err.message; var is_optional = context.is_preview || resource.options.optional; diff --git a/test/solidus.js b/test/solidus.js index a2e687c..b9b4fdc 100644 --- a/test/solidus.js +++ b/test/solidus.js @@ -322,9 +322,21 @@ describe( 'Solidus', function(){ nock('https://solid.us').get('/error/mandatory?test=3').reply(401, {error: 'Nice try'}); nock('https://solid.us').get('/error/optional?test=3').reply(200, {test: 3}); s_request.get('/with_resource_error?test=3') - .expect(401) + .expect(500) .end(function(err, res) { - assert(res.text.indexOf('Oh no (401)!') > -1); + assert(res.text.indexOf('Oh no (500)!') > -1); + callback(err); + }); + }, + function(callback) { + // Bad status is available in context + nock('https://solid.us').get('/error/mandatory?test=3').reply(401, {error: 'Nice try'}); + nock('https://solid.us').get('/error/optional?test=3').reply(200, {test: 3}); + s_request.get('/with_resource_error.json?test=3') + .expect(500) + .end(function(err, res) { + assert.equal(res.body.error.status, 500); + assert.equal(res.body.error.message.status, 401); callback(err); }); }, @@ -1219,9 +1231,9 @@ describe( 'Solidus', function(){ nock('https://solid.us').get('/error/mandatory?test=3').reply(401, {error: 'Nice try'}); nock('https://solid.us').get('/error/optional?test=3').reply(200, {test: 3}); s_request.get('/with_resource_error?test=3') - .expect(401) + .expect(500) .end(function(err, res) { - assert.equal(res.text, '401 Unauthorized'); + assert.equal(res.text, '500 Internal Server Error'); callback(err); }); }