feat(api): implement new api handler

This commit is contained in:
nils måsén 2023-10-21 19:35:41 +02:00
parent 72e437f173
commit 47091761a5
17 changed files with 571 additions and 294 deletions

36
pkg/api/prelude/errors.go Normal file
View file

@ -0,0 +1,36 @@
package prelude
import "net/http"
type errorResponse struct {
Error string `json:"error"`
Code ErrorCode `json:"code"`
Status int `json:"-"`
}
const internalErrorPayload string = `{ "error": "API internal error, check logs", "code": "API_INTERNAL_ERROR" }`
type ErrorCode string
var (
ErrUpdateRunning = errorResponse{
Code: "UPDATE_RUNNING",
Error: "Update already running",
Status: http.StatusConflict,
}
ErrNotFound = errorResponse{
Code: "NOT_FOUND",
Error: "Endpoint is not registered to a handler",
Status: http.StatusNotFound,
}
ErrInvalidToken = errorResponse{
Code: "INVALID_TOKEN",
Error: "The supplied token does not match the configured auth token",
Status: http.StatusUnauthorized,
}
ErrMissingToken = errorResponse{
Code: "MISSING_TOKEN",
Error: "No authentication token was supplied",
Status: http.StatusUnauthorized,
}
)