aboutsummaryrefslogtreecommitdiff
path: root/internal/api/error.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api/error.go')
-rw-r--r--internal/api/error.go23
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,
+ })
+}