feat(backend): global error handling & request validation layer (RFC … - #34
Conversation
…7807)
Replace the ad-hoc {error, success} exception contract with RFC 7807
(application/problem+json) across the API: GlobalExceptionHandler now
returns ProblemDetail (type/title/status/detail + an `errors` extension
for field/parameter validation), and the security filter-chain's 401/403
handlers render the same shape since they run outside the DispatcherServlet.
Also closes the bean-validation gaps: every @RequestBody DTO is now
validated with @Valid, request DTOs gained missing constraints, and
@RequestParam/@PathVariable identifiers are validated via @validated +
jakarta.validation on ClientController/SkilledWorkerController.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Thanks — this is a great, well-scoped improvement. The RFC 7807 move + the validation cleanup makes the API more consistent and safer for consumers. I’ll merge once a few small, important issues are addressed (see below). Required changes (please address)
Optional / suggestions
Next steps / merge plan
Meanwhile, this is a high-quality PR and moves the API in the right direction. Get this done and it'll be ready for merge. |
- All GlobalExceptionHandler methods now return ResponseEntity<ProblemDetail> with the HTTP status set explicitly, instead of relying on the framework to infer it from ProblemDetail's own status field. - ProblemDetails.of and .asMap now both write timestamp as the same ISO-8601 string, instead of an Instant object on one path and a string on the other. - Added an asMap overload that accepts an optional errors map, so the security filter-chain handlers (401/403) can produce the identical JSON shape as GlobalExceptionHandler if a validation-flavoured 401/403 ever needs field-level detail. - scheduleAvailability's LocalDateTime @RequestParams now declare @DateTimeFormat(iso = ISO.DATE_TIME) for predictable parsing. - Made the problem `type` base URI configurable via guildworkman.problem-details.type-base (PROBLEM_TYPE_BASE env var), wired through a small ProblemDetailsConfig bean since ProblemDetails is a static utility shared by non-Spring-managed call sites. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
@meshackyaro I pushed with all required fixes: explicit ResponseEntity status on every handler, consistent ISO-8601 timestamps, @DateTimeFormat on the date params, confirmed @validated coverage is complete, and an errors-aware asMap overload for the security handlers. Also made the problem type base URI configurable (optional item). No stale {success} assertions found in tests. |
meshackyaro
left a comment
There was a problem hiding this comment.
All 6 required changes addressed in follow-up commit; RFC 7807 compliance complete with comprehensive validation hardening.
Well done @CmxTop and thank you for contributing to Guildworkman
Replace the ad-hoc {error, success} exception contract with RFC 7807 (application/problem+json) across the API: GlobalExceptionHandler now returns ProblemDetail (type/title/status/detail + an
errorsextension for field/parameter validation), and the security filter-chain's 401/403 handlers render the same shape since they run outside the DispatcherServlet.Also closes the bean-validation gaps: every @RequestBody DTO is now validated with @Valid, request DTOs gained missing constraints, and @RequestParam/@PathVariable identifiers are validated via @validated + jakarta.validation on ClientController/SkilledWorkerController.
Closes #25