{"id":15061795,"url":"https://github.com/alancesar/gin-error-handler-sample","last_synced_at":"2026-01-01T23:51:21.463Z","repository":{"id":101475627,"uuid":"429929238","full_name":"alancesar/gin-error-handler-sample","owner":"alancesar","description":"Handling with errors in gin-gonic","archived":false,"fork":false,"pushed_at":"2022-01-11T21:03:29.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-22T02:15:02.362Z","etag":null,"topics":["error-handling","gin","gin-gonic","go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alancesar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2021-11-19T20:43:37.000Z","updated_at":"2021-11-19T21:09:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"0f298911-b1c6-46c1-b097-58adc6cdaeb8","html_url":"https://github.com/alancesar/gin-error-handler-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alancesar%2Fgin-error-handler-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alancesar%2Fgin-error-handler-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alancesar%2Fgin-error-handler-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alancesar%2Fgin-error-handler-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alancesar","download_url":"https://codeload.github.com/alancesar/gin-error-handler-sample/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243723320,"owners_count":20337352,"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","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":["error-handling","gin","gin-gonic","go","golang"],"created_at":"2024-09-24T23:25:12.406Z","updated_at":"2026-01-01T23:51:21.431Z","avatar_url":"https://github.com/alancesar.png","language":"Go","readme":"# Handling errors in gin-gonic\n\n## Starting application\n```shell\ngo mod dowload\ngo run main.go\n```\n\n## Request\n\n```shell\ncurl --location --request POST 'http://localhost:8080/api' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n    \"id\": \"some-id\",\n    \"fail_database\": false,\n    \"fail_service\": false\n}'\n```\n\n## Errors\nThere are two errors struct: `database.Err` and `service.Err`.\nThey implement `error` interface `Error() string` and `Is(target error) bool`,\nreturning true if `target` is `pkg.InternalErr`.\n\n## Middleware\nThe middleware `ErrorHandlerMiddleware()` get the errors from gin-gonic context.\nIf present, check if it is a `pkg.InternalErr`.\nCase true, return an internal server error; otherwise, return bad request.  \nThis middleware also checks if `err.Err` is a `database.Err` and prints additional logs.\n\n## Handler\nThe `api.Handler` call run `c.Error(err)` to append errors in gin-gonic context.\n\n## Additional information\n- [errors.Is documentation](https://pkg.go.dev/errors#Is)\n- [gin-gonic bindings](https://github.com/gin-gonic/gin#model-binding-and-validation)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falancesar%2Fgin-error-handler-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falancesar%2Fgin-error-handler-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falancesar%2Fgin-error-handler-sample/lists"}