fix(httpapi): phase 1 compliance — ERR-01, SEC-04, CDN client, scheduler docs
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -2,9 +2,15 @@ package httpapi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
internalErrorDetail = "an internal error occurred"
|
||||
badGatewayDetail = "upstream request failed"
|
||||
)
|
||||
|
||||
// Problem is RFC 9457 application/problem+json.
|
||||
type Problem struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
@@ -34,3 +40,19 @@ func writeJSON(w http.ResponseWriter, status int, v any) {
|
||||
func writeNoContent(w http.ResponseWriter) {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// writeInternalError logs err server-side and returns a generic 500 problem (ERR-01).
|
||||
func writeInternalError(w http.ResponseWriter, operation string, err error) {
|
||||
if err != nil {
|
||||
log.Printf("httpapi: %s: %v", operation, err)
|
||||
}
|
||||
writeProblem(w, http.StatusInternalServerError, "Internal Error", internalErrorDetail)
|
||||
}
|
||||
|
||||
// writeBadGateway logs err server-side and returns a generic 502 problem (ERR-01).
|
||||
func writeBadGateway(w http.ResponseWriter, operation string, err error) {
|
||||
if err != nil {
|
||||
log.Printf("httpapi: %s: %v", operation, err)
|
||||
}
|
||||
writeProblem(w, http.StatusBadGateway, "Bad Gateway", badGatewayDetail)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user