{"id":16485645,"url":"https://github.com/estrada9166/graphql-custom-error-response","last_synced_at":"2025-10-27T18:31:10.386Z","repository":{"id":89469239,"uuid":"128597913","full_name":"estrada9166/graphql-custom-error-response","owner":"estrada9166","description":"Create custom errors response","archived":false,"fork":false,"pushed_at":"2018-04-08T04:48:34.000Z","size":118,"stargazers_count":12,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-28T17:07:20.986Z","etag":null,"topics":["express","graphql","graphql-api","graphql-express","graphql-js","graphql-server","nodejs"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/estrada9166.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-08T04:34:09.000Z","updated_at":"2023-08-03T16:26:31.000Z","dependencies_parsed_at":"2023-03-13T18:09:29.849Z","dependency_job_id":null,"html_url":"https://github.com/estrada9166/graphql-custom-error-response","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/estrada9166/graphql-custom-error-response","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/estrada9166%2Fgraphql-custom-error-response","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/estrada9166%2Fgraphql-custom-error-response/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/estrada9166%2Fgraphql-custom-error-response/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/estrada9166%2Fgraphql-custom-error-response/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/estrada9166","download_url":"https://codeload.github.com/estrada9166/graphql-custom-error-response/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/estrada9166%2Fgraphql-custom-error-response/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281319954,"owners_count":26481094,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-27T02:00:05.855Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express","graphql","graphql-api","graphql-express","graphql-js","graphql-server","nodejs"],"created_at":"2024-10-11T13:26:33.532Z","updated_at":"2025-10-27T18:31:10.381Z","avatar_url":"https://github.com/estrada9166.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Create custom error response\n\n \n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n\n\n# Step by step\n\n[Check this post to try it step by step](https://medium.com/@estrada9166/return-custom-errors-with-status-code-on-graphql-45fca360852)\n\n# How to run it\n+ Clone this repo.\n+ `npm install`.\n+ `npm run dev`.\n+ Visit on your browser `http://localhost:7000/graphql`.\n+ Make this query:\n    ```\n    {\n      test {\n        test\n      }\n    } \n    ```\n\n## Main idea\nThe main idea is to return a custom error with the `statusCode` on the response, also you can send any extra field, to do it you need to change just 2 files:\n\n### Constants.js\n```js\nexports.errorType = {\n  UNAUTHORIZED: {\n    message: 'Authentication is needed to get requested response.',\n    statusCode: 401\n    // add here any extra field\n  }\n}\n```\n### App.js\n```js\nformatError: (err) =\u003e {\n  const error = getErrorCode(err.message)\n  return ({ \n    message: error.message, \n    statusCode: error.statusCode \n    // add here err.\u003cYOUR_EXTRA_FIELD_CREATED_ON_CONSTANTS\u003e\n  })\n}\n```\n\nIn this case we just want to return a `message` and a `statusCode`\n\n![New user](images/custom-error.png)\n\n## License\n### The MIT License\n\nCopyright (c) 2018 Alejandro Estrada\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Festrada9166%2Fgraphql-custom-error-response","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Festrada9166%2Fgraphql-custom-error-response","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Festrada9166%2Fgraphql-custom-error-response/lists"}