MCPcopy Index your code
hub / github.com/Monibuca/engine / ReturnError

Function ReturnError

util/socket.go:66–88  ·  view source on GitHub ↗
(code int, msg string, rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

64}
65
66func ReturnError(code int, msg string, rw http.ResponseWriter, r *http.Request) {
67 query := r.URL.Query()
68 isJson := query.Get("format") == "json"
69 if isJson {
70 if err := json.NewEncoder(rw).Encode(APIError{code, msg}); err != nil {
71 json.NewEncoder(rw).Encode(APIError{
72 Code: APIErrorJSONEncode,
73 Message: err.Error(),
74 })
75 }
76 } else {
77 switch true {
78 case code == 0:
79 http.Error(rw, msg, http.StatusOK)
80 case code/10 == 404:
81 http.Error(rw, msg, http.StatusNotFound)
82 case code > 5000:
83 http.Error(rw, msg, http.StatusInternalServerError)
84 default:
85 http.Error(rw, msg, http.StatusBadRequest)
86 }
87 }
88}
89func ReturnFetchList[T any](fetch func() []T, rw http.ResponseWriter, r *http.Request) {
90 query := r.URL.Query()
91 isYaml := query.Get("format") == "yaml"

Callers 11

API_streamMethod · 0.92
API_closeStreamMethod · 0.92
API_getConfigMethod · 0.92
API_modifyConfigMethod · 0.92
API_updateConfigMethod · 0.92
API_stop_pushMethod · 0.92
API_stop_subscribeMethod · 0.92
API_replay_rtpdumpMethod · 0.92
API_replay_tsMethod · 0.92
API_replay_mp4Method · 0.92
ReturnOKFunction · 0.85

Calls 2

ErrorMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected