A community based topic aggregation platform built on atproto
at main 25 lines 597 B view raw
1package xrpc 2 3import ( 4 "encoding/json" 5 "log" 6 "net/http" 7) 8 9// Error represents an XRPC error response 10type Error struct { 11 Error string `json:"error"` 12 Message string `json:"message"` 13} 14 15// WriteError writes an XRPC error response with the given status code 16func WriteError(w http.ResponseWriter, statusCode int, errorType, message string) { 17 w.Header().Set("Content-Type", "application/json") 18 w.WriteHeader(statusCode) 19 if err := json.NewEncoder(w).Encode(Error{ 20 Error: errorType, 21 Message: message, 22 }); err != nil { 23 log.Printf("Failed to encode XRPC error response: %v", err) 24 } 25}