Skip to content

Commit

Permalink
Merge pull request hapijs#209 from walmartlabs/user/eran
Browse files Browse the repository at this point in the history
Tests
  • Loading branch information
geek committed Nov 1, 2012
2 parents b96282f + fa4d5fe commit e83ef1c
Show file tree
Hide file tree
Showing 3 changed files with 362 additions and 309 deletions.
9 changes: 8 additions & 1 deletion lib/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,14 @@ internals.Error.passThrough = function (code, payload, contentType) {
return response;
};

var err = new internals.Error(code, 'Pass-through', { toResponse: format });
var err = new internals.Error(500, 'Pass-through', { toResponse: format }); // 500 code is only used internally and is not exposed when sent

err.passThrough = {
code: code,
payload: payload,
contentType: contentType
};

return err;
};

Expand Down
16 changes: 13 additions & 3 deletions test/integration/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ describe('Request', function () {
{ method: 'GET', path: '/custom', config: { handler: customErrorHandler } },
]);

var makeRequest = function (path, callback) {
var makeRequest = function (method, path, callback) {

var next = function (res) {

return callback(res);
};

server.inject({
method: 'GET',
method: method,
url: path
}, next);
}
Expand All @@ -45,11 +45,21 @@ describe('Request', function () {

it('returns custom error response', function (done) {

makeRequest('/custom', function (rawRes) {
makeRequest('GET', '/custom', function (rawRes) {

var headers = parseHeaders(rawRes.raw.res);
expect(headers['Content-Type']).to.equal('text/plain');
done();
});
});

it('returns valid OPTIONS response', function (done) {

makeRequest('OPTIONS', '/custom', function (rawRes) {

var headers = parseHeaders(rawRes.raw.res);
expect(headers['Access-Control-Allow-Origin']).to.equal('*');
done();
});
});
});
Loading

0 comments on commit e83ef1c

Please sign in to comment.