Skip to content

Return custom HTTP status codesΒ #1873

@rb090

Description

@rb090

Hi πŸ‘‹,

I start using your library to provide a GraphQL API endpoint. I am working on the error handling right now. I read your documentation Exceptions and Partial Data regarding this. Returning errors like described there works very well.

I am coming from the REST world and there I am used to return corresponding HTTP Status codes in case that sth went wrong. So fe. when my code throws an IllegalArgumentException somewhere, I like to return fe. HTTP status code 400 (bad request) and an error json:

{
  "title": "Sth went wrong",
  "message": "Some message here explaining more"
}

Can you please tell me whether sth similar is possible in graphql and with your library?

Probably not with DataFetcherResult because there, HTTP status code is always 200.

Can I throw somehow a custom graphql exception which produces a similar result like I would like it to have?

Thanks in regards for any suggestion on this. Please be patient with me, it is my 1st GQL server project πŸ™ˆ

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions