aboutsummaryrefslogtreecommitdiff
path: root/pkg/api
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/api')
-rw-r--r--pkg/api/api0/errors.go7
-rw-r--r--pkg/api/api0/playerinfo.go9
2 files changed, 11 insertions, 5 deletions
diff --git a/pkg/api/api0/errors.go b/pkg/api/api0/errors.go
index ad58224..2d06719 100644
--- a/pkg/api/api0/errors.go
+++ b/pkg/api/api0/errors.go
@@ -1,5 +1,7 @@
package api0
+import "fmt"
+
// ErrorCode represents a known Northstar error code.
type ErrorCode string
@@ -59,3 +61,8 @@ func (n ErrorCode) Message() string {
return string(n)
}
}
+
+// Messagef returns Message() with additional text appended after ": ".
+func (n ErrorCode) Messagef(format string, a ...interface{}) string {
+ return n.Message() + ": " + fmt.Sprintf(format, a...)
+}
diff --git a/pkg/api/api0/playerinfo.go b/pkg/api/api0/playerinfo.go
index b47ef4c..9a35bf3 100644
--- a/pkg/api/api0/playerinfo.go
+++ b/pkg/api/api0/playerinfo.go
@@ -3,7 +3,6 @@ package api0
import (
"crypto/sha256"
"encoding/hex"
- "fmt"
"net/http"
"strconv"
"time"
@@ -84,7 +83,7 @@ func (h *Handler) handlePlayer(w http.ResponseWriter, r *http.Request) {
respJSON(w, r, http.StatusBadRequest, map[string]any{
"success": false,
"error": ErrorCode_BAD_REQUEST,
- "msg": fmt.Sprintf("%s: id param is required", ErrorCode_BAD_REQUEST.Message()),
+ "msg": ErrorCode_BAD_REQUEST.Messagef("id param is required"),
})
return
}
@@ -127,7 +126,7 @@ func (h *Handler) handlePlayer(w http.ResponseWriter, r *http.Request) {
respJSON(w, r, http.StatusInternalServerError, map[string]any{
"success": false,
"error": ErrorCode_INTERNAL_SERVER_ERROR,
- "msg": fmt.Sprintf("%s: failed to read pdata hash from storage", ErrorCode_INTERNAL_SERVER_ERROR.Message()),
+ "msg": ErrorCode_INTERNAL_SERVER_ERROR.Message(),
})
return
}
@@ -152,7 +151,7 @@ func (h *Handler) handlePlayer(w http.ResponseWriter, r *http.Request) {
respJSON(w, r, http.StatusInternalServerError, map[string]any{
"success": false,
"error": ErrorCode_INTERNAL_SERVER_ERROR,
- "msg": fmt.Sprintf("%s: failed to parse pdata from storage", ErrorCode_INTERNAL_SERVER_ERROR.Message()),
+ "msg": ErrorCode_INTERNAL_SERVER_ERROR.Messagef("failed to parse pdata from storage"),
})
return
}
@@ -167,7 +166,7 @@ func (h *Handler) handlePlayer(w http.ResponseWriter, r *http.Request) {
respJSON(w, r, http.StatusInternalServerError, map[string]any{
"success": false,
"error": ErrorCode_INTERNAL_SERVER_ERROR,
- "msg": fmt.Sprintf("%s: failed to encode pdata as json", ErrorCode_INTERNAL_SERVER_ERROR.Message()),
+ "msg": ErrorCode_INTERNAL_SERVER_ERROR.Messagef("failed to encode pdata as json"),
})
return
}