Skip to content

Commit

Permalink
NYT API Example Error Handling
Browse files Browse the repository at this point in the history
This change will handle more error codes returned from NYT API than just 403 HTTP errors.
Remove NYT API from the unit tests since it would depend on NYT's endpoint which may not be predictable.
  • Loading branch information
YasharF committed Jan 27, 2019
1 parent 7c70f95 commit 5a2fa6e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
4 changes: 2 additions & 2 deletions controllers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ exports.getNewYorkTimes = (req, res, next) => {
};
request.get({ url: 'http://api.nytimes.com/svc/books/v2/lists', qs: query }, (err, request, body) => {
if (err) { return next(err); }
if (request.statusCode === 403) {
return next(new Error('Invalid New York Times API Key'));
if (request.statusCode >= 400) {
return next(new Error(`New York Times API - ${body}`));
}
const books = JSON.parse(body).results;
res.render('api/nyt', {
Expand Down
8 changes: 0 additions & 8 deletions test/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ describe('GET /api/lastfm', () => {
});
});

describe('GET /api/nyt', () => {
it('should return 200 OK', (done) => {
request(app)
.get('/api/nyt')
.expect(200, done);
});
});

describe('GET /api/twilio', () => {
it('should return 200 OK', (done) => {
request(app)
Expand Down

0 comments on commit 5a2fa6e

Please sign in to comment.