{"id":24554008,"url":"https://github.com/fkucukkara/errorresponseworkshop","last_synced_at":"2026-02-27T07:44:59.641Z","repository":{"id":271033905,"uuid":"909483671","full_name":"fkucukkara/errorResponseWorkshop","owner":"fkucukkara","description":"This repository demonstrates an implementation of **error response handling** in .NET Minimal APIs using `ProblemDetails`.","archived":false,"fork":false,"pushed_at":"2025-05-01T09:32:34.000Z","size":8,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-01T10:33:02.939Z","etag":null,"topics":["csharp","error-handling","netcore-webapi","problem-details"],"latest_commit_sha":null,"homepage":"","language":"C#","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/fkucukkara.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,"zenodo":null}},"created_at":"2024-12-28T20:54:52.000Z","updated_at":"2025-05-01T09:32:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"38732391-3bc3-4be7-9393-fcaf9cde2394","html_url":"https://github.com/fkucukkara/errorResponseWorkshop","commit_stats":null,"previous_names":["fkucukkara/errorresponseworkshop"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fkucukkara/errorResponseWorkshop","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fkucukkara%2FerrorResponseWorkshop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fkucukkara%2FerrorResponseWorkshop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fkucukkara%2FerrorResponseWorkshop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fkucukkara%2FerrorResponseWorkshop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fkucukkara","download_url":"https://codeload.github.com/fkucukkara/errorResponseWorkshop/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fkucukkara%2FerrorResponseWorkshop/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29887849,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-27T05:38:26.446Z","status":"ssl_error","status_checked_at":"2026-02-27T05:38:25.235Z","response_time":57,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["csharp","error-handling","netcore-webapi","problem-details"],"created_at":"2025-01-23T02:17:03.279Z","updated_at":"2026-02-27T07:44:59.616Z","avatar_url":"https://github.com/fkucukkara.png","language":"C#","readme":"# Error Response Handling in Minimal APIs\n\nThis repository demonstrates an implementation of **error response handling** in .NET Minimal APIs using `ProblemDetails`. It showcases how to handle exceptions and status codes in a structured and user-friendly way while adhering to best practices.\n\n## Features\n- **Standardized Error Responses**: Uses `ProblemDetails` to generate error responses conforming to the [RFC 7807](https://datatracker.ietf.org/doc/html/rfc7807) standard.\n- **Automatic Error Handling**: Simplifies the handling of exceptions and HTTP status codes with middleware integration.\n- **Minimal API Integration**: Lightweight and concise implementation for modern .NET applications.\n\n## Advantages\n1. **Improved API Consumer Experience**:\n   - Provides consistent and meaningful error messages to API clients.\n   - Helps consumers of the API understand what went wrong and how to resolve issues.\n\n2. **Standardized Format**:\n   - The use of `ProblemDetails` ensures that error responses follow a predictable structure, which is crucial for debugging and integration with client applications.\n\n3. **Reduced Boilerplate**:\n   - The integration of `ProblemDetails`, exception handling, and status code pages reduces the need for custom error-handling code.\n\n4. **Extensibility**:\n   - Easily customizable to include additional error details, such as trace IDs, request URLs, or custom metadata.\n\n## Implementation\nThe implementation uses Minimal APIs and middleware to handle exceptions and status codes.\n\n### Code Example\n```csharp\nvar builder = WebApplication.CreateBuilder(args);\n\nbuilder.Services.AddProblemDetails();\n\nvar app = builder.Build();\n\napp.UseExceptionHandler();\napp.UseStatusCodePages();\n\napp.MapGet(\"/users/{id:int}\", (int id)\n    =\u003e id \u003c= 0 ? Results.BadRequest() : Results.Ok(new User(id)));\n\napp.Run();\n\ninternal record User(int Id);\n```\n\n### Explanation\n1. **`AddProblemDetails`**:\n   - Registers the `ProblemDetails` middleware, which generates standardized error responses.\n\n2. **`UseExceptionHandler`**:\n   - Handles unhandled exceptions and generates error responses.\n\n3. **`UseStatusCodePages`**:\n   - Adds support for returning proper responses for HTTP status codes (e.g., `400 Bad Request`, `404 Not Found`).\n\n4. **Endpoint**:\n   - Example endpoint `/users/{id:int}`:\n     - Returns `400 Bad Request` if `id \u003c= 0`.\n     - Returns a `200 OK` response with a user object if `id \u003e 0`.\n\n## How to Run\n\n1. Clone the repository:\n   ```bash\n   git clone https://github.com/fkucukkara/errorResponseWorkshop.git\n   cd src/API\n   ```\n\n2. Build and run the application:\n   ```bash\n   dotnet run\n   ```\n\n3. Test the endpoints:\n   - Valid request:\n     ```\n     GET /users/1\n     Response: { \"id\": 1 }\n     ```\n   - Invalid request:\n     ```\n     GET /users/-1\n     Response: HTTP 400 with ProblemDetails\n     ```\n\n## Example Error Response\nFor an invalid request, the API generates a response in the `ProblemDetails` format:\n\n```json\n{\n  \"type\": \"https://tools.ietf.org/html/rfc7231#section-6.5.1\",\n  \"title\": \"Bad Request\",\n  \"status\": 400,\n  \"detail\": \"The request parameters are invalid.\",\n  \"instance\": \"/users/-1\"\n}\n```\n\n## License\n[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n\nThis project is licensed under the MIT License, which allows you to freely use, modify, and distribute the code. See the [`LICENSE`](LICENSE) file for full details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffkucukkara%2Ferrorresponseworkshop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffkucukkara%2Ferrorresponseworkshop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffkucukkara%2Ferrorresponseworkshop/lists"}