{"id":25421556,"url":"https://github.com/reecerussell/go-errors","last_synced_at":"2025-05-13T18:51:16.408Z","repository":{"id":57633318,"uuid":"413911558","full_name":"reecerussell/go-errors","owner":"reecerussell","description":"A simple interface return descriptive errors from HTTP handlers.","archived":false,"fork":false,"pushed_at":"2021-10-15T10:05:59.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-20T06:26:56.555Z","etag":null,"topics":["errors","golang","http"],"latest_commit_sha":null,"homepage":"","language":"Go","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/reecerussell.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}},"created_at":"2021-10-05T17:14:21.000Z","updated_at":"2024-04-20T16:39:25.000Z","dependencies_parsed_at":"2022-08-31T13:21:37.896Z","dependency_job_id":null,"html_url":"https://github.com/reecerussell/go-errors","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reecerussell%2Fgo-errors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reecerussell%2Fgo-errors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reecerussell%2Fgo-errors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reecerussell%2Fgo-errors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reecerussell","download_url":"https://codeload.github.com/reecerussell/go-errors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239195493,"owners_count":19598037,"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":["errors","golang","http"],"created_at":"2025-02-16T20:48:57.693Z","updated_at":"2025-02-16T20:48:58.232Z","avatar_url":"https://github.com/reecerussell.png","language":"Go","readme":"[![Go Report Card](https://goreportcard.com/badge/github.com/reecerussell/go-errors)](https://goreportcard.com/badge/github.com/reecerussell/go-errors)\r\n[![codecov](https://codecov.io/gh/reecerussell/go-errors/branch/master/graph/badge.svg)](https://codecov.io/gh/reecerussell/go-errors)\r\n[![Go Docs](https://godoc.org/github.com/reecerussell/go-errors?status.svg)](https://godoc.org/github.com/reecerussell/go-errors)\r\n\r\n# Errors\r\n\r\nA simple interface return descriptive errors from HTTP handlers. Expanding on the `error` interface, `Error` provides APIs to set the `type` and `message` of the error, as well as an optional `paramName` property.\r\n\r\n## Get started\r\n\r\nIt's super simple to integrate with your APIs, first all install the module into your project.\r\n\r\n```\r\n\u003e go get -u github.com/reecerussell/go-errors\r\n```\r\n\r\nThen as an example, here's how you can use it in your handlers.\r\n\r\n```go\r\n\r\nimport (\r\n    \"net/http\"\r\n\r\n    \"github.com/reecerussell/go-errors/errors\"\r\n)\r\n\r\n...\r\n\r\nfunc myHandler(w http.ResponseWriter, r *http.Request) {\r\n    var data MyDataModel\r\n    err := json.NewDecoder(r.Body).Decode(\u0026data)\r\n    if err != nil {\r\n        // If the body is not valid, create a new validation error\r\n        // with a type. Then write it to the response with the helper.\r\n        err = errors.NewValidation(err).\r\n            SetType(\"invalid body\")\r\n\r\n        errors.WriteResponse(w, err)\r\n        return\r\n    }\r\n\r\n    err = MyProcess(\u0026data) // returns standard error\r\n    if err != nil {\r\n        // The WriteResponse helper can also write standard errors.\r\n        errors.WriteResponse(w, err)\r\n    }\r\n}\r\n\r\n```\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freecerussell%2Fgo-errors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freecerussell%2Fgo-errors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freecerussell%2Fgo-errors/lists"}