mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-16 15:10:12 +01:00
feat(api): implement new api handler
This commit is contained in:
parent
72e437f173
commit
47091761a5
17 changed files with 571 additions and 294 deletions
36
pkg/api/prelude/errors.go
Normal file
36
pkg/api/prelude/errors.go
Normal 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,
|
||||
}
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue