diff options
| author | RanXom <saiyedshizain@gmail.com> | 2026-07-13 17:53:46 +0530 |
|---|---|---|
| committer | RanXom <saiyedshizain@gmail.com> | 2026-07-13 17:53:46 +0530 |
| commit | f108043068c8818c616cc2e760f53839d4ba9b01 (patch) | |
| tree | 01dce4dbdfd531f3eb60c920c3232c8bbafd43f4 /internal/api/error.go | |
| parent | d87995c3629cac4671b05073915214f45d0c7112 (diff) | |
| download | galleryd-f108043068c8818c616cc2e760f53839d4ba9b01.tar.xz galleryd-f108043068c8818c616cc2e760f53839d4ba9b01.zip | |
refactor(api): return structured error responses
Diffstat (limited to 'internal/api/error.go')
| -rw-r--r-- | internal/api/error.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/api/error.go b/internal/api/error.go new file mode 100644 index 0000000..b00f326 --- /dev/null +++ b/internal/api/error.go @@ -0,0 +1,23 @@ +package api + +import ( + "encoding/json" + "net/http" +) + +type errorResponse struct { + Error string `json:"error"` +} + +func writeError( + w http.ResponseWriter, + status int, + message string, +) { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(status) + + _ = json.NewEncoder(w).Encode(errorResponse{ + Error: message, + }) +} |