1
0
Fork 1
mirror of https://github.com/git-pkgs/proxy.git synced 2026-06-02 08:38:17 -04:00
pkg-proxy/internal/server
Andrew Nesbitt 8d2740624f
Structured JSON error responses for API endpoints (#110)
* Structured JSON error responses for API endpoints

API handlers returned errors via http.Error (text/plain) with ad-hoc
strings, while the mirror API used a different {"error": "..."} shape
and leaked internal err.Error() text to clients.

Add ErrorResponse{Code, Message} with stable codes (BAD_REQUEST,
NOT_FOUND, UPSTREAM_ERROR, INTERNAL_ERROR) and writeError/badRequest/
notFound/internalError helpers. Convert all JSON API handlers in
api.go, browse.go, mirror_api.go and the /stats endpoint. Enrichment
failures now report 502 UPSTREAM_ERROR rather than 500.

Protocol handlers in internal/handler/ are deliberately unchanged
since npm/pip/cargo clients expect their own response formats, not
JSON. HTML page handlers in server.go also keep text/plain.

Swagger @Failure annotations updated and docs regenerated.

Fixes #76

* Convert validatePackagePath errors to JSON in API handlers
2026-05-03 09:42:03 +01:00
..
static Add Container, Debian, RPM handlers and enrichment API 2026-01-29 19:35:15 +00:00
templates Escape user-controlled strings in browse source JavaScript 2026-03-12 11:59:14 +00:00
api.go Structured JSON error responses for API endpoints (#110) 2026-05-03 09:42:03 +01:00
api_test.go Validate package paths before database lookups (#109) 2026-05-03 09:14:18 +01:00
browse.go Structured JSON error responses for API endpoints (#110) 2026-05-03 09:42:03 +01:00
browse_bench_test.go Use archives.OpenBytes in browse handler to cut buffer copies (#107) 2026-05-03 09:29:42 +01:00
browse_test.go Use archives.OpenBytes in browse handler to cut buffer copies (#107) 2026-05-03 09:29:42 +01:00
dashboard.go Sort the ecosystems list for presentation in the UI 2026-04-06 18:06:16 -04:00
errors.go Structured JSON error responses for API endpoints (#110) 2026-05-03 09:42:03 +01:00
errors_test.go Structured JSON error responses for API endpoints (#110) 2026-05-03 09:42:03 +01:00
eviction.go Enforce max_size config with LRU cache eviction 2026-04-30 18:09:01 +01:00
eviction_test.go Enforce max_size config with LRU cache eviction 2026-04-30 18:09:01 +01:00
middleware.go Refactoring and features 2026-02-03 22:40:40 +00:00
middleware_test.go Add handler download flow and server utility tests 2026-03-17 20:31:54 +00:00
mirror_api.go Structured JSON error responses for API endpoints (#110) 2026-05-03 09:42:03 +01:00
mirror_api_test.go Add MaxBytesReader to mirror API HandleCreate (#105) 2026-05-02 18:00:25 +01:00
packages_list_test.go Fix all golangci-lint issues across the codebase (#32) 2026-03-18 10:59:29 +00:00
resolve.go Validate package paths before database lookups (#109) 2026-05-03 09:14:18 +01:00
resolve_test.go Validate package paths before database lookups (#109) 2026-05-03 09:14:18 +01:00
server.go Structured JSON error responses for API endpoints (#110) 2026-05-03 09:42:03 +01:00
server_test.go Add mirror command and API for selective package mirroring 2026-04-13 09:01:04 +01:00
static.go Add Container, Debian, RPM handlers and enrichment API 2026-01-29 19:35:15 +00:00
swagger_gen.go Add generated OpenAPI docs support 2026-03-12 11:49:31 +00:00
templates.go Lazy-load HTML templates behind sync.Once (#59) 2026-04-06 13:06:25 +01:00
templates_test.go Apply 'go fmt' as suggested in CONTRIBUTING.md. 2026-04-18 07:43:22 -04:00