api calls
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
// Error is the single shape every failure takes. Clients get a stable machine
|
||||
// readable code plus a human message. A self-hosted bot instance can branch on
|
||||
// readable code plus a human message; a self-hosted bot instance can branch on
|
||||
// the code without parsing prose.
|
||||
type Error struct {
|
||||
Code string `json:"code"`
|
||||
@@ -46,6 +46,12 @@ func WriteError(w http.ResponseWriter, status int, code, message string) {
|
||||
}
|
||||
}
|
||||
|
||||
// writeErrorBody writes just the envelope, for callers that have already sent
|
||||
// their own status code and headers.
|
||||
func writeErrorBody(w http.ResponseWriter, code, message string) error {
|
||||
return json.NewEncoder(w).Encode(errorEnvelope{Error{Code: code, Message: message}})
|
||||
}
|
||||
|
||||
// WriteJSON sends a success payload.
|
||||
func WriteJSON(w http.ResponseWriter, status int, v any) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
|
||||
Reference in New Issue
Block a user