Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

closes #107: Swagger should not override error handling. #131

Merged
merged 1 commit into from Jun 11, 2014

Conversation

jsdevel
Copy link
Contributor

@jsdevel jsdevel commented Jun 10, 2014

No description provided.

@fehguy
Copy link
Contributor

fehguy commented Jun 10, 2014

should this move into the develop branch?

@jsdevel
Copy link
Contributor Author

jsdevel commented Jun 10, 2014

@fehguy this would create a breaking change so I can understand your desire there. How willing are you to bump the major version for this alone? I'd like to use this sooner rather than later.

@jsdevel
Copy link
Contributor Author

jsdevel commented Jun 10, 2014

@fehguy if we need to make updates to the 2.x.x branch, we could always create a branch for that based on the commit prior to this one.

@tracker1
Copy link

As mentioned in #130 I'd update the example to...

throw {status:400, message:'missing required foo'}

And the error handler...

function(err,req,res,next) {
  res.send(err.status || 500, {error:err})
}

oh yeah, and bump at least the minor to the next odd number in the package.json

@tracker1
Copy link

Would also suggest considering adding the changes to Swagger.prototype.errors in #130 .. or removing Swagger.prototype.errors altogether.

@jsdevel
Copy link
Contributor Author

jsdevel commented Jun 10, 2014

@tracker1 I updated the sample to your liking.

This PR really just removes the error handling from swagger and places it back in the hands of express. Given that, I think changes to Swagger.prototype.errors warrant another PR. Thoughts?

@hillct
Copy link

hillct commented Jun 10, 2014

While I'm not in a place where I can test this, the code change looks solid (on visual inspection).

I wonder if addition of a flag to revert back to the old error handling behavior, such that this would no longer be a breaking change, is worthwhile? I have very mixed feelings about this as the code un-cleanliness such a flag would introduce offends me almost to the point where I'm pained to suggest that kind of thing. Another option would be to implement the old-style error handling as a separate module such that existing swagger-node-express users would not be stranded without and upgrade path, but would merely be required to import the separate error handler.

@jsdevel
Copy link
Contributor Author

jsdevel commented Jun 10, 2014

@hillct I'm with you on the flags.

I don't see too much of a difference between express's default error handler and the one swagger provides. The pain point with this breakage is that calls to swagger.setErrorHandler will throw an error. Perhaps a console.error within the body of swagger.setErrorHandler with an instruction to use app.use instead would be better?

@enterline
Copy link

maybe a swagger.unsetErrorHandler function that sets this.errorHandler to null. Then in addMethod do the try-catch if this.errorHandler !== null otherwise just do the callback. That way it is not a breaking change.

@jsdevel
Copy link
Contributor Author

jsdevel commented Jun 11, 2014

@fehguy I added .setErrorHandler() back to swagger. Calls to it will now log a warning in the console instructing the user to use standard express middleware instead. I've also added a note in the README about this change for 2.1.0 and bumped the version in package.json.

Can you create a 2.0.x branch prior to merging this? Doing so will allow us to handle issues that arise for that version. Thanks!

@fehguy
Copy link
Contributor

fehguy commented Jun 11, 2014

@timruffles
Copy link

LGTM!

@jsdevel
Copy link
Contributor Author

jsdevel commented Jun 11, 2014

Thanks @fehguy @timruffles ! I'm looking forward to getting this merged and published so we can start referencing it ;)

fehguy added a commit that referenced this pull request Jun 11, 2014
closes #107: Swagger should not override error handling.
@fehguy fehguy merged commit cf00739 into swagger-api:master Jun 11, 2014
@fehguy
Copy link
Contributor

fehguy commented Jun 11, 2014

Note, this commit produces a 2.1.x version of the swagger module, and has breaking changes with 2.0.x!

@fehguy
Copy link
Contributor

fehguy commented Jun 11, 2014

pushed 2.1.0 to npmjs.org

@jsdevel
Copy link
Contributor Author

jsdevel commented Jun 11, 2014

Awesome @fehguy! Thank you 😄

@jsdevel jsdevel deleted the removing-error-handling branch June 11, 2014 15:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants