Skip to content

Commit

Permalink
Allow providers to customize status code on error.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianreavis committed Aug 16, 2015
1 parent 8be2ff9 commit 728b0ab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/TileRequestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ TileRequestHandler.prototype['GET'] = function(server, req, callback) {
return done(404, BUFFER_NOPROVIDER, {});
}
self.provider.serve(server, req, function(err, buffer, headers) {
if (err) return done(500, new Buffer(err.message || err, 'utf8'), {});
if (err) return done(err.statusCode || 500, new Buffer(err.message || err, 'utf8'), {});
renderedHeaders = headers || {};
renderedBuffer = buffer;
setImmediate(callback);
Expand Down
16 changes: 16 additions & 0 deletions test/TileRequestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,22 @@ describe('TileRequestHandler', function() {
done();
});
});
it('should return statusCode attached to provider error if available', function(done) {
var mockServer = new TileServer();
var mockRequest = TileRequest.parse('/layer/1/2/3/tile.png');
var handler = new TileRequestHandler();
handler.use({
serve: function(server, req, callback) {
var err = new Error('My error');
err.statusCode = 999;
callback(err);
}
});
handler.GET(mockServer, mockRequest, function(status, buffer, headers) {
assert.equal(status, 999);
done();
});
});
it('should skip transforms if provider fails', function(done) {
var mockServer = new TileServer();
var mockRequest = TileRequest.parse('/layer/1/2/3/tile.png');
Expand Down

0 comments on commit 728b0ab

Please sign in to comment.