fix(httpapi): phase 1 compliance — ERR-01, SEC-04, CDN client, scheduler docs

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Denozordec
2026-05-20 00:21:16 +07:00
co-authored by Cursor
parent aff27e8f7b
commit 1dd713514c
8 changed files with 67 additions and 19 deletions
+22
View File
@@ -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)
}