aboutsummaryrefslogtreecommitdiff
path: root/pkg/api/api0/api.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/api/api0/api.go')
-rw-r--r--pkg/api/api0/api.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/pkg/api/api0/api.go b/pkg/api/api0/api.go
index 818f6b9..398ac17 100644
--- a/pkg/api/api0/api.go
+++ b/pkg/api/api0/api.go
@@ -151,6 +151,23 @@ func (h *Handler) checkLauncherVersion(r *http.Request) bool {
return semver.Compare(rver, mver) >= 0
}
+// respFail writes a {success:false,error:ErrorObj} response with the provided
+// response status.
+func respFail(w http.ResponseWriter, r *http.Request, status int, obj ErrorObj) {
+ if rid, ok := hlog.IDFromRequest(r); ok {
+ respJSON(w, r, status, map[string]any{
+ "success": false,
+ "error": obj,
+ "request_id": rid.String(),
+ })
+ } else {
+ respJSON(w, r, status, map[string]any{
+ "success": false,
+ "error": obj,
+ })
+ }
+}
+
// respJSON writes the JSON encoding of obj with the provided response status.
func respJSON(w http.ResponseWriter, r *http.Request, status int, obj any) {
if r.Method == http.MethodHead {