Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This branch implements an error handling framework. This is based on the framework implemented in WODIN which seems to work quite well! The idea is that any requests which cannot be completed successfully should cause an Error to be thrown. This Error will be dealt with by the
handleError
method which will ensure that the appropriate JSON error response and status code are returned.Key changes:
GroutError
class. This is for errors which we throw deliberately e.g. in the case of a bad request, or unknown resource requests. Parameters to this class include message, ErrorType and status code. These parameters are used byhandleError
to build the error Response.handleError
- given a thrown error, builds a "Porcelain-style" response with error, status code and error type. If the error is an instance ofGroutError
its message is returned in the response. If not, then this is an unexpected error, and we don't want to return its raw error message to the client. so we include a generic message, along with a unique error code.handleError
includes message (including error code), type and stack in tokens to be logged bymorgan
. This means that we can find the stack corresponding to an unexpected error code in the logs if required.asyncControllerHandler
- this allowshandleError
to be triggered when the error is thrown asynchronously to the initial request call. It does this by catching any error, and ensuring thatnext
is called with the error as parameter. This handler should be used by any controller method which isasync
.notFound
- utility function for throwing a GroutError for any 404 scenario. Used by both the router and theTileController
(for the case where the tile request was for unknown data).jsonResponse
utility for returning JSON error and success responses in our standard Porcelain format. Update to the index response to use this.