{"id":13413265,"url":"https://github.com/AmuzaTkts/jsonapi-errors","last_synced_at":"2025-03-14T19:31:50.305Z","repository":{"id":57496859,"uuid":"62879735","full_name":"AmuzaTkts/jsonapi-errors","owner":"AmuzaTkts","description":"Go bindings based on the JSON API errors reference","archived":false,"fork":false,"pushed_at":"2016-11-17T16:02:12.000Z","size":8,"stargazers_count":14,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2024-07-31T20:52:11.372Z","etag":null,"topics":["go","golang","json-api","jsonapi-errors"],"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/AmuzaTkts.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":"2016-07-08T10:08:58.000Z","updated_at":"2023-09-26T23:00:03.000Z","dependencies_parsed_at":"2022-09-03T02:30:49.394Z","dependency_job_id":null,"html_url":"https://github.com/AmuzaTkts/jsonapi-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/AmuzaTkts%2Fjsonapi-errors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmuzaTkts%2Fjsonapi-errors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmuzaTkts%2Fjsonapi-errors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmuzaTkts%2Fjsonapi-errors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AmuzaTkts","download_url":"https://codeload.github.com/AmuzaTkts/jsonapi-errors/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221498727,"owners_count":16833055,"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":["go","golang","json-api","jsonapi-errors"],"created_at":"2024-07-30T20:01:36.428Z","updated_at":"2024-10-26T05:30:38.193Z","avatar_url":"https://github.com/AmuzaTkts.png","language":"Go","readme":"# jsonapi-errors [![GoDoc](https://godoc.org/github.com/golang/gddo?status.svg)](http://godoc.org/github.com/AmuzaTkts/jsonapi-errors) [![Build Status](https://travis-ci.org/AmuzaTkts/jsonapi-errors.svg?branch=master)](https://travis-ci.org/AmuzaTkts/jsonapi-errors) [![Coverage Status](https://coveralls.io/repos/github/AmuzaTkts/jsonapi-errors/badge.svg?branch=master)](https://coveralls.io/github/AmuzaTkts/jsonapi-errors?branch=master) [![Go ReportCard](https://goreportcard.com/badge/github.com/AmuzaTkts/jsonapi-errors)](https://goreportcard.com/report/github.com/AmuzaTkts/jsonapi-errors)\n\nThis package provides error bindings based on the [JSON API](http://jsonapi.org/format/#errors)\nreference.\n\nThe package provides two main structs that you can use on your application, the\n`Error` and `Bag` structs. When returning errors from your API you should return\na `Bag` containing one or more errors.\n\n```Go\nbag := NewBagWithError(502, \"Oops =(\")\njsonStr, _ := json.Marshal(bag)\n```\n\nThe above code will return the following JSON structure:\n\n```JSON\n{\n  \"errors\": [\n    {\n      \"detail\": \"Oops =(\",\n      \"status\": \"502\"\n    }\n  ],\n  \"status\": \"502\"\n}\n```\n\n## Multiple errors\nThis package adds the possibility to add multiple errors with different status\ncodes. The package will check for the range of the errors and will set the main\nstatus key to the lower bound of the error class.\n\nEg: If add an error `501` and `502`, the main status key will be `500`.\n\n```Go\nbag := NewBag()\nbag.AddError(501, \"Server Error 1\")\nbag.AddError(502, \"Server Error 2\")\n\njsonStr, _ := json.Marshal(bag)\n```\n\nWill return:\n```JSON\n{\n    \"errors\": [\n        {\n            \"detail\": \"Server Error 1\",\n            \"status\": \"501\"\n        },\n        {\n            \"detail\": \"Server Error 2\",\n            \"status\": \"502\"\n        }\n    ],\n    \"status\": \"500\"\n}\n```\n\nIt's also possible to have errors of different classes(`400` and `500` for example),\nin this case the package will silently return `400` as the main status.\n\n```Go\nbag := NewBag()\nbag.AddError(401, \"Client Error 1\")\nbag.AddError(502, \"Server Error 1\")\n\njsonStr, _ := json.Marshal(bag)\n```\n\n```JSON\n{\n    \"errors\": [\n        {\n            \"detail\": \"Client Error 1\",\n            \"status\": \"401\"\n        },\n        {\n            \"detail\": \"Server Error 1\",\n            \"status\": \"502\"\n        }\n    ],\n    \"status\": \"400\"\n}\n```\n","funding_links":[],"categories":["Relational Databases","JSON","Utilities","工具库","实用工具","實用工具"],"sub_categories":["Search and Analytic Databases","Advanced Console UIs","HTTP Clients","SQL 查询语句构建库","交流","检索及分析资料库","高级控制台界面","高級控制台界面","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAmuzaTkts%2Fjsonapi-errors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAmuzaTkts%2Fjsonapi-errors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAmuzaTkts%2Fjsonapi-errors/lists"}