Background
Follow-up from PR #751 review (thread: #751 (comment)).
Different API endpoints currently return error information in different shapes — a bare JSON string (BadRequest("…")), a DTO with a Message property (e.g. CopyEnvBuildResponseDto), serialized exception objects (StatusCode(500, exception)), and ASP.NET ProblemDetails (title/detail). To cope, the client ApiCaller.ExtractErrorMessage (src/Dorc.Core/ApiCaller.cs) has to probe several candidate fields, which is fragile and easy to get wrong.
Goal
Standardize on a single error contract returned by every API endpoint, so clients read one field.
Proposed scope
- Define one error-response shape (e.g.
{ "error": "…" }, or ASP.NET ProblemDetails with a single agreed field) and document it.
- Update controllers to return that shape consistently for 4xx/5xx, and stop returning raw exception objects / stack traces to clients (use a correlation id; log details server-side). This overlaps with a separate security concern about verbose error/stack-trace disclosure across the API (
DefaultExceptionHandler and several controllers returning StatusCode(500, e) / error + " - " + ex).
- Simplify
ApiCaller.ExtractErrorMessage to read the single field once the server side is consistent.
- Add/adjust tests.
Notes
Background
Follow-up from PR #751 review (thread: #751 (comment)).
Different API endpoints currently return error information in different shapes — a bare JSON string (
BadRequest("…")), a DTO with aMessageproperty (e.g.CopyEnvBuildResponseDto), serialized exception objects (StatusCode(500, exception)), and ASP.NET ProblemDetails (title/detail). To cope, the clientApiCaller.ExtractErrorMessage(src/Dorc.Core/ApiCaller.cs) has to probe several candidate fields, which is fragile and easy to get wrong.Goal
Standardize on a single error contract returned by every API endpoint, so clients read one field.
Proposed scope
{ "error": "…" }, or ASP.NETProblemDetailswith a single agreed field) and document it.DefaultExceptionHandlerand several controllers returningStatusCode(500, e)/error + " - " + ex).ApiCaller.ExtractErrorMessageto read the single field once the server side is consistent.Notes