Write middleware for handling tmdb errors #116

Open
opened 2019-07-26 19:50:09 +00:00 by KevinMidboe · 1 comment
KevinMidboe commented 2019-07-26 19:50:09 +00:00 (Migrated from github.com)

Do like started on movieInfo and showInfo. There we check the status codes right after our requests to themoviedb api.

Improvements:

  • Check if the error is a http error.
  • Create error response dictonary to throw http status code and error message from.
  • Type safety

Example:

.catch(error => {
  if (error.status === 401) {
    throw new Error('Unathorized tmdb request, please check api key.')
  } else  if (error.status === 404) {
    throw new Error(`Could not find a movie with id: ${identifier}`)
  }
 
  throw new Error('Unexpected error has occured:', error.message)
})
Do like started on `movieInfo` and `showInfo`. There we check the status codes right after our requests to themoviedb api. Improvements: - Check if the error is a http error. - Create error response dictonary to throw http status code and error message from. - Type safety Example: ```javascript .catch(error => { if (error.status === 401) { throw new Error('Unathorized tmdb request, please check api key.') } else if (error.status === 404) { throw new Error(`Could not find a movie with id: ${identifier}`) } throw new Error('Unexpected error has occured:', error.message) }) ```
KevinMidboe commented 2019-07-26 19:54:29 +00:00 (Migrated from github.com)

Save for database errors

Save for database errors
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: KevinMidboe/seasonedShows#116
No description provided.