marky

Lightweight bookmarking + plaintext archive
Log | Files | Refs | README | LICENSE

commit bba73c3bc1d03c7cb008377ffa30b5214b32f696
parent d0730de5f0b43d056ece1fa2fcf3e058e14b4f31
Author: David Eisinger <[email protected]>
Date:   Mon, 20 Oct 2025 11:39:42 -0400

Use 422 instead of 502 for failure

Diffstat:
MREADME.md | 2+-
Minternal/api.go | 6+++---
Minternal/update_archive_test.go | 4++--
3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md @@ -82,7 +82,7 @@ Create a new bookmark. - `200 OK` if the URL already exists; the archive is refreshed and `updated_at` is touched (idempotent by URL) - `400 Bad Request` for invalid payload - `415 Unsupported Media Type` if not JSON - - `502 Bad Gateway` if archiver fails to fetch content + - `422 Unprocessable Entity` if archiver fails to fetch content - `500 Internal Server Error` on unexpected errors - Response body: ``` diff --git a/internal/api.go b/internal/api.go @@ -704,7 +704,7 @@ func NewHandlerWithConfig(db *DB, cfg HandlerConfig) (http.Handler, error) { } } if err != nil { - http.Error(w, "failed to archive URL", http.StatusBadGateway) + http.Error(w, "failed to archive URL", http.StatusUnprocessableEntity) return } } @@ -945,7 +945,7 @@ func NewHandlerWithConfig(db *DB, cfg HandlerConfig) (http.Handler, error) { } txt, err := ArchiveToText(ctx, b.URL) if err != nil { - http.Error(w, "failed to fetch archive", http.StatusBadGateway) + http.Error(w, "failed to fetch archive", http.StatusUnprocessableEntity) return } if err := db.SaveArchive(ctx, id64, txt); err != nil { @@ -1032,7 +1032,7 @@ func NewHandlerWithConfig(db *DB, cfg HandlerConfig) (http.Handler, error) { shouldArchive = true _, txt, err := TitleAndText(ctx, req.URL) if err != nil { - http.Error(w, "failed to archive URL", http.StatusBadGateway) + http.Error(w, "failed to archive URL", http.StatusUnprocessableEntity) return } newArchive = txt diff --git a/internal/update_archive_test.go b/internal/update_archive_test.go @@ -77,8 +77,8 @@ func TestUpdateURL_RefetchArchiveAndRejectOnError(t *testing.T) { req, _ := http.NewRequest(http.MethodPut, srv.URL+"/bookmarks/"+itoa(id), bytes.NewReader([]byte("{\"url\":\""+failing.URL+"\",\"title\":\"First\"}"))) req.Header.Set("Content-Type", "application/json") rs2, _ := client.Do(req) - if rs2.StatusCode != http.StatusBadGateway { - t.Fatalf("expected 502 on fetch failure, got %d", rs2.StatusCode) + if rs2.StatusCode != http.StatusUnprocessableEntity { + t.Fatalf("expected 422 on fetch failure, got %d", rs2.StatusCode) } rs2.Body.Close()