HSLdevcom / OpenTripPlanner

An open source multi-modal trip planner
http://www.opentripplanner.org
Other
33 stars 31 forks source link

Fix graphqlerror capture #204

Closed jolkkola closed 6 years ago

jolkkola commented 6 years ago

The purpose of this pull request is to prevent the Sentry capture phase from crashing if the underlying error is not ExceptionWhileDataFetching but something else instead. These types of error usually come up when the incoming QraphQL query is not properly built or it does not match the schema.

Previously the server would return an HTTP 500 result with a message similar to: "java.lang.ClassCastException: graphql.validation.ValidationError cannot be cast to graphql.ExceptionWhileDataFetching graphql.validation.ValidationError cannot be cast to graphql.ExceptionWhileDataFetching"

Now the server still returns an HTTP 500 result but with a better error message:

{
    "errors": [
        {
            "validationErrorType": "FieldUndefined",
            "message": "Validation error of type FieldUndefined: Field asdf is undefined",
            "errorType": "ValidationError",
            "locations": [
                {
                    "line": 135,
                    "column": 62
                }
            ]
        }
    ]
}