Fix TypeError: Cannot read property 'statusCode' of undefined