Skip to content
Myr

Added specs for errors with text/plain and application/json

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by visionmedia · committed by visionmedia · parent 405097d · Browse files · 2 files+40 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+40 added−12 removed

  • tests:+38 added−10 removed
  • other:+2 added−2 removed

2 files+40 added−12 removed

modified:lib/express/request.js+2 added-2 removed
120 unmodified lines
121 var accept = this.header('accept')122 if (!accept) return true123 return arguments.any(function(path){124 var type = mime.type(path)125 return accept.indexOf(type) !== -1 ||126 accept.indexOf(type.split('/')[0] + '/*') !== -1125 return accept.indexOf(type) !== -1 ||126 accept.indexOf(type.split('/')[0] + '/*') !== -1127 })128 },129 130 /**
273 unmodified lines
modified:spec/spec.request.js+38 added-10 removed
258 unmodified lines
259 err.message.should.eql 'whoop'260 end261 end262 263 describe 'when not accepting common mime types'264 it 'should render the default 500 status body'265 var headers = { headers: { accept: 'text/plain' }}266 disable('throw exceptions')267 enable('show exceptions')268 get('/', function(){269 this.error(new Error('fail!'))270 })271 get('/', headers).body.should.eql 'Internal Server Error'272 get('/', headers).status.should.eql 500273 end274 end275 276 describe 'when accepting "html"'277 describe 'with "show exceptions" enabled'278 it 'should render the show-exceptions page'279 disable('throw exceptions')
5 unmodified lines
285 get('/').status.should.eql 500286 end287 end288 276 describe 'when not accepting "html"'277 it 'should render the default 500 status body'278 var headers = { headers: { accept: 'text/plain' }}289 describe 'with "throw exceptions" enabled'290 it 'should re-throw the exception'291 enable('show exceptions')292 enable('throw exceptions')293 get('/', function(){294 this.error(new Error('fail!'))295 })296 -{ get('/') }.should.throw_error Error, 'fail!'297 end298 end299 end300 301 describe 'when accepting "text/plain"'302 describe 'with "show exceptions" enabled'303 it 'should render a text representation of the error'304 disable('throw exceptions')305 enable('show exceptions')306 get('/', function(){307 this.error(new Error('fail!'))308 })284 get('/', headers).body.should.eql 'Internal Server Error'285 get('/', headers).status.should.eql 500309 get('/', { headers: { accept: 'text/plain' }}).body.should.include '500 Error: fail!'310 get('/').status.should.eql 500311 end312 end288 289 describe 'with "throw exceptions" enabled'290 it 'should re-throw the exception'313 end314 315 describe 'when accepting "application/json"'316 describe 'with "show exceptions" enabled'317 it 'should render a text representation of the error'318 disable('throw exceptions')319 enable('show exceptions')292 enable('throw exceptions')320 get('/', function(){321 this.error(new Error('fail!'))322 })296 -{ get('/') }.should.throw_error Error, 'fail!'323 get('/', { headers: { accept: 'application/json' }}).body.should.include '{ "error": { "message": "fail!" }}'324 get('/').status.should.eql 500 325 end326 end327 end328
69 unmodified lines