{"id":15748170,"url":"https://github.com/prongbang/fibererror","last_synced_at":"2025-08-03T03:10:08.204Z","repository":{"id":218767106,"uuid":"747309380","full_name":"prongbang/fibererror","owner":"prongbang","description":"Create a custom response using the error interface in Go","archived":false,"fork":false,"pushed_at":"2024-04-12T08:47:42.000Z","size":28,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T22:52:04.413Z","etag":null,"topics":["custom-error","error","fibererror","go-custom-error","goerror","gofiber-error"],"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/prongbang.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":"2024-01-23T17:17:50.000Z","updated_at":"2024-01-23T17:22:35.000Z","dependencies_parsed_at":"2024-06-21T16:54:48.846Z","dependency_job_id":"575264eb-ae26-4412-a8db-433fc2117147","html_url":"https://github.com/prongbang/fibererror","commit_stats":null,"previous_names":["prongbang/fibererror"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prongbang%2Ffibererror","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prongbang%2Ffibererror/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prongbang%2Ffibererror/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prongbang%2Ffibererror/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prongbang","download_url":"https://codeload.github.com/prongbang/fibererror/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246429447,"owners_count":20775805,"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":["custom-error","error","fibererror","go-custom-error","goerror","gofiber-error"],"created_at":"2024-10-04T05:40:49.611Z","updated_at":"2025-08-03T03:10:08.193Z","avatar_url":"https://github.com/prongbang.png","language":"Go","funding_links":["https://www.buymeacoffee.com/prongbang"],"categories":[],"sub_categories":[],"readme":"# fibererror 🚨\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/prongbang/fibererror)](https://goreportcard.com/report/github.com/prongbang/fibererror)\n[![Go Reference](https://pkg.go.dev/badge/github.com/prongbang/fibererror.svg)](https://pkg.go.dev/github.com/prongbang/fibererror)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Go Version](https://img.shields.io/github/go-mod/go-version/prongbang/fibererror.svg)](https://golang.org)\n\n\u003e Elegant error response handling for Fiber applications with support for custom errors and internationalization.\n\n## ✨ Features\n\n- 🎯 **Simple Integration** - Easy to integrate with existing Fiber applications\n- 🔧 **Custom Error Types** - Create your own error types with custom codes\n- 🌍 **i18n Support** - Built-in internationalization for error messages\n- ⚡ **High Performance** - Optimized for speed and efficiency\n- 🎨 **Flexible Configuration** - Customizable response formats\n- 📦 **Standard HTTP Errors** - Pre-defined standard HTTP error responses\n\n## 📊 Performance\n\n```shell\nBenchmarkFiberErrorResponse_Response-10    \t  186163\t      7115 ns/op\nBenchmarkBuildInErrorResponse_Response-10      \t  143802\t      7479 ns/op\n```\n\n## 📦 Installation\n\n```shell\ngo get github.com/prongbang/fibererror\n```\n\n## 🚀 Quick Start\n\n### Basic Usage with Standard HTTP Status\n\n```go\npackage main\n\nimport (\n    \"github.com/prongbang/goerror\"\n    \"github.com/prongbang/fibererror\"\n    \"github.com/gofiber/fiber/v2\"\n)\n\nfunc main() {\n    app := fiber.New()\n    response := fibererror.New()\n    \n    app.Get(\"/\", func(c *fiber.Ctx) error {\n        return response.With(c).Response(goerror.NewUnauthorized())\n    })\n    \n    _ = app.Listen(\":3000\")\n}\n```\n\n## 🛠️ Advanced Usage\n\n### Custom Error Types\n\nCreate your own error types with custom codes:\n\n```go\npackage main\n\nimport (\n    \"github.com/prongbang/goerror\"\n    \"github.com/prongbang/fibererror\"\n    \"github.com/gofiber/fiber/v2\"\n    \"net/http\"\n)\n\n// Define custom error type\ntype CustomError struct {\n    goerror.Body\n}\n\nfunc (c *CustomError) Error() string {\n    return c.Message\n}\n\nfunc NewCustomError() error {\n    return \u0026CustomError{\n        Body: goerror.Body{\n            Code:    \"CUS001\",\n            Message: \"Custom error occurred\",\n        },\n    }\n}\n\n// Define custom response handler\ntype customResponse struct{}\n\nfunc (c *customResponse) Response(ctx *fiber.Ctx, err error) error {\n    switch resp := err.(type) {\n    case *CustomError:\n        return ctx.Status(http.StatusBadRequest).JSON(resp)\n    }\n    return nil\n}\n\nfunc NewCustomResponse() fibererror.Custom {\n    return \u0026customResponse{}\n}\n\nfunc main() {\n    app := fiber.New()\n    \n    // Configure custom response\n    customResp := NewCustomResponse()\n    response := fibererror.New(\u0026fibererror.Config{\n        Custom: \u0026customResp,\n    })\n    \n    app.Get(\"/\", func(c *fiber.Ctx) error {\n        return response.With(c).Response(NewCustomError())\n    })\n    \n    _ = app.Listen(\":3000\")\n}\n```\n\n### 🌍 Internationalization Support\n\nLocalize error messages based on `Accept-Language` header:\n\n#### 1. Create localization files\n\n`localize/en.yaml`:\n```yaml\nCUS001: Custom error 001\n```\n\n`localize/th.yaml`:\n```yaml\nCUS001: ข้อผิดพลาดแบบกำหนดเอง 001\n```\n\n#### 2. Configure i18n with fibererror\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/gofiber/contrib/fiberi18n/v2\"\n    \"github.com/gofiber/fiber/v2\"\n    \"github.com/prongbang/fibererror\"\n    \"golang.org/x/text/language\"\n)\n\nfunc main() {\n    app := fiber.New()\n    \n    // Configure i18n middleware\n    app.Use(fiberi18n.New(\u0026fiberi18n.Config{\n        RootPath:        \"./localize\",\n        AcceptLanguages: []language.Tag{language.Thai, language.English},\n        DefaultLanguage: language.English,\n    }))\n    \n    // Configure fibererror with i18n\n    customResp := NewCustomResponse()\n    response := fibererror.New(\u0026fibererror.Config{\n        Custom: \u0026customResp,\n        I18n: \u0026fibererror.I18n{\n            Enabled: true,\n            Localize: func(ctx *fiber.Ctx, code string) (string, error) {\n                return fiberi18n.Localize(ctx, code)\n            },\n        },\n    })\n    \n    app.Get(\"/\", func(c *fiber.Ctx) error {\n        return response.With(c).Response(NewCustomError())\n    })\n    \n    err := app.Listen(\":3000\")\n    if err != nil {\n        fmt.Println(\"Error starting server:\", err)\n    }\n}\n```\n\n## 📝 Configuration Options\n\n### fibererror.Config\n\n| Option | Type | Description |\n|--------|------|-------------|\n| `Custom` | `*Custom` | Custom error response handler |\n| `I18n` | `*I18n` | Internationalization configuration |\n\n### fibererror.I18n\n\n| Option | Type | Description |\n|--------|------|-------------|\n| `Enabled` | `bool` | Enable/disable i18n support |\n| `Localize` | `func(*fiber.Ctx, string) (string, error)` | Localization function |\n\n## 🔍 Examples\n\n### Handling Multiple Error Types\n\n```go\nfunc (c *customResponse) Response(ctx *fiber.Ctx, err error) error {\n    switch resp := err.(type) {\n    case *CustomError:\n        return ctx.Status(http.StatusBadRequest).JSON(resp)\n    case *AuthError:\n        return ctx.Status(http.StatusUnauthorized).JSON(resp)\n    case *ValidationError:\n        return ctx.Status(http.StatusUnprocessableEntity).JSON(resp)\n    default:\n        return ctx.Status(http.StatusInternalServerError).JSON(fiber.Map{\n            \"code\": \"INTERNAL_ERROR\",\n            \"message\": \"An unexpected error occurred\",\n        })\n    }\n}\n```\n\n### Error Response Format\n\nStandard error response structure:\n\n```json\n{\n    \"code\": \"CUS001\",\n    \"message\": \"Custom error message\"\n}\n```\n\nWith additional fields:\n\n```json\n{\n    \"code\": \"VAL001\",\n    \"message\": \"Validation failed\",\n    \"details\": {\n        \"field\": \"email\",\n        \"reason\": \"invalid format\"\n    }\n}\n```\n\n## 🤝 Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## 📄 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## 💖 Support the Project\n\nIf you find this package helpful, please consider supporting it:\n\n[![\"Buy Me A Coffee\"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/prongbang)\n\n## 🔗 Related Projects\n\n- [goerror](https://github.com/prongbang/goerror) - Error handling utilities for Go\n- [Fiber](https://github.com/gofiber/fiber) - Express-inspired web framework\n- [fiberi18n](https://github.com/gofiber/contrib/tree/main/fiberi18n) - i18n middleware for Fiber\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprongbang%2Ffibererror","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprongbang%2Ffibererror","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprongbang%2Ffibererror/lists"}