Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add distinct error classes #2690

Closed
sebgie opened this issue May 5, 2014 · 1 comment · Fixed by #2704
Closed

Add distinct error classes #2690

sebgie opened this issue May 5, 2014 · 1 comment · Fixed by #2704
Assignees
Labels
affects:api Affects the Ghost API
Milestone

Comments

@sebgie
Copy link
Contributor

sebgie commented May 5, 2014

This issue is an improvement to our error handling suggested by @appleYaks in #2643 (comment). We are using the following errors with the corresponding error code in api/index.js:

  • BadRequest: 400
  • Unauthorized: 401
  • NoPermission: 403
  • NotFound: 404
  • RequestEntityTooLarge: 413
  • ValidationError: 422
  • EmailError: 500
  • InternalServerError: 500

All existing API errors should be replaced by an error class that holds the corresponding error code. Internal API requests are expected to deal with the error object returned and api.requestHandler() has to convert the object into a valid JSON response.

@ErisDS ErisDS added the api label May 5, 2014
@ErisDS ErisDS added this to the 0.4 API milestone May 5, 2014
@darvelo
Copy link
Contributor

darvelo commented May 7, 2014

Seems you can actually tell when to catch only certain error types:

promise.then(function() {
    throw new CustomError('oops!');
}).catch(CustomError, function(e) {
    // Only catch CustomError instances
    // all other types of errors will propagate automatically
}).catch(function(e) {
    // Catch other errors
})

sebgie added a commit to sebgie/Ghost that referenced this issue May 9, 2014
closes TryGhost#2690
- added new error classes
- moved errorhandling.js to /errors/index.js
- changed API errors to use new classes
- updated tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects:api Affects the Ghost API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants