Custom GraphQL exceptions

Custom GraphQL exceptions


0

I’m trying to create a custom exception when GraphQL throws its owns. The default GraphQL exception response I got is (except for the fillings):

{
    "errors": [
        {
            "message": "Validation error of type WrongType: argument 'inputLocals.localId' with value 'IntValue{value=7777800}' is not a valid 'Int' - Expected value to be in the Integer range but it was '7777800' @ 'getLocals'",
            "locations": [
                {
                    "line": 1,
                    "column": 25
                }
            ],
            "extensions": {
                "classification": "ValidationError"
            }
        }
    ],
    "data": null
}

So this is an error I got when I surpass the int limit, and I want this to be like this:

{
    "code": "400",
    "reason": "BAD_REQUEST",
    "message": "/localId 7777800 is not less or equal to 99999",
    "status": "",
    "referenceError": ""
}

I am using the Kickstart GraphQL library, I have checked for some GraphQL Error Handler but it ain’t as expected (same format). I want the exception to appear when I use this query in my resolver:

  @Override
    public OutputLocals getLocals(InputLocals inputLocals) throws CustomGraphQLError {
        int localId = inputLocals.localId();
        if (localId > 99999) {
            throw new CustomGraphQLError("fields matching the JSON above");
        }
     // Rest of code


Load 7 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *