Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

488
Views
Apollo-Server display errors in a clean mannor

I'm pretty sure that the question is self explanatory. I'm using 'apollo-server-core' 3.6.5

Errors I want to get

 {
      "errors": [
        {
          "message": "Syntax Error: Unexpected <EOF>.",
          "locations": [
            {
              "line": 1,
              "column": 1
            }
          ]
        }
      ]
    }

Errors I do get

{
  "errors": [
    {
      "message": "GraphQL operations must contain a non-empty `query` or a `persistedQuery` extension.",
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "GraphQLError: GraphQL operations must contain a non-empty `query` or a `persistedQuery` extension.",
            "    at processGraphQLRequest (C:\\Users\\XXXX\\Documents\\Github\\XXXX-XXX\\node_modules\\apollo-server-core\\src\\requestPipeline.ts:204:7)",
            "    at processTicksAndRejections (node:internal/process/task_queues:96:5)",
            "    at async processHTTPRequest (C:\\Users\\XXXX\\Documents\\Github\\XXXX-XXXX\\node_modules\\apollo-server-core\\src\\runHttpQuery.ts:346:24)"
          ]
        }
      }
    }
  ]
}

My initial thought was parse the error into an object, and map out any undesirables like so

 const msg = JSON.parse(error.message).errors.map((err:any) => err = {message: err.message});

But that dose not work as it dose not tell you where the mistake occurred + it seems unnecessary to use JSON.parse and then stringify'ing it right back.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The apollo docs cover error handling. https://www.apollographql.com/docs/apollo-server/data/errors/#throwing-errors

You can create a custom error like this:

import { ApolloError } from 'apollo-server-errors';

throw new ApolloError('My error message', 'MY_ERROR_CODE', myCustomExtensions);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!