snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
This commit is contained in:
192
server/pkg/errors/kind.go
Normal file
192
server/pkg/errors/kind.go
Normal file
@@ -0,0 +1,192 @@
|
||||
package errors
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type (
|
||||
kind uint8
|
||||
)
|
||||
|
||||
const (
|
||||
// internal (unspecified) error
|
||||
// these errors yield HTTP status 500 and hide
|
||||
// details unless in development environment
|
||||
KindInternal kind = iota
|
||||
|
||||
// Data validation error
|
||||
KindInvalidData
|
||||
|
||||
// Requested data not found
|
||||
KindNotFound
|
||||
|
||||
// Stale data submitted
|
||||
// Internally data was already updated or is locked in another session
|
||||
KindStaleData
|
||||
|
||||
// Data already exists
|
||||
KindDuplicateData
|
||||
|
||||
// Data sensitivity related issue
|
||||
KindSensitiveData
|
||||
|
||||
// Access control
|
||||
KindUnauthorized
|
||||
|
||||
// Expecting authenticated user
|
||||
KindUnauthenticated
|
||||
|
||||
// External system failure
|
||||
KindExternal
|
||||
|
||||
// store error
|
||||
KindStore
|
||||
|
||||
// object store (file upload/download)
|
||||
KindObjStore
|
||||
|
||||
// automation error
|
||||
KindAutomation
|
||||
)
|
||||
|
||||
// translates error kind into http status
|
||||
func (k kind) httpStatus() int {
|
||||
switch k {
|
||||
case KindInvalidData, KindSensitiveData:
|
||||
return http.StatusBadRequest
|
||||
|
||||
case KindNotFound:
|
||||
return http.StatusNotFound
|
||||
|
||||
case KindStaleData:
|
||||
return http.StatusConflict
|
||||
|
||||
case KindDuplicateData:
|
||||
return http.StatusConflict
|
||||
|
||||
case KindUnauthorized:
|
||||
return http.StatusUnauthorized
|
||||
|
||||
case KindUnauthenticated:
|
||||
return http.StatusForbidden
|
||||
|
||||
default:
|
||||
return http.StatusInternalServerError
|
||||
}
|
||||
}
|
||||
|
||||
func Internal(m string, aa ...interface{}) *Error {
|
||||
return err(KindInternal, fmt.Sprintf(m, aa...))
|
||||
}
|
||||
|
||||
func Store(m string, aa ...interface{}) *Error {
|
||||
return err(KindStore, fmt.Sprintf(m, aa...))
|
||||
}
|
||||
|
||||
func ObjStore(m string, aa ...interface{}) *Error {
|
||||
return err(KindObjStore, fmt.Sprintf(m, aa...))
|
||||
}
|
||||
|
||||
func InvalidData(m string, aa ...interface{}) *Error {
|
||||
return err(KindInvalidData, fmt.Sprintf(m, aa...))
|
||||
}
|
||||
|
||||
func NotFound(m string, aa ...interface{}) *Error {
|
||||
return err(KindNotFound, fmt.Sprintf(m, aa...))
|
||||
}
|
||||
|
||||
func StaleData(m string, aa ...interface{}) *Error {
|
||||
return err(KindStaleData, fmt.Sprintf(m, aa...))
|
||||
}
|
||||
|
||||
func DuplicateData(m string, aa ...interface{}) *Error {
|
||||
return err(KindDuplicateData, fmt.Sprintf(m, aa...))
|
||||
}
|
||||
|
||||
func SensitiveData(m string, aa ...interface{}) *Error {
|
||||
return err(KindSensitiveData, fmt.Sprintf(m, aa...))
|
||||
}
|
||||
|
||||
func Unauthorized(m string, aa ...interface{}) *Error {
|
||||
return err(KindUnauthorized, fmt.Sprintf(m, aa...))
|
||||
}
|
||||
|
||||
func Unauthenticated(m string, aa ...interface{}) *Error {
|
||||
return err(KindUnauthenticated, fmt.Sprintf(m, aa...))
|
||||
}
|
||||
|
||||
func External(m string, aa ...interface{}) *Error {
|
||||
return err(KindExternal, fmt.Sprintf(m, aa...))
|
||||
}
|
||||
|
||||
func Automation(m string, aa ...interface{}) *Error {
|
||||
return err(KindAutomation, fmt.Sprintf(m, aa...))
|
||||
}
|
||||
|
||||
func IsKind(err error, k kind) bool {
|
||||
t, ok := err.(*Error)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
return t.kind == k
|
||||
}
|
||||
|
||||
// IsAny returns true if error is of type *Error
|
||||
func IsAny(err error) bool {
|
||||
var is bool
|
||||
if err != nil {
|
||||
_, is = err.(*Error)
|
||||
}
|
||||
|
||||
return is
|
||||
}
|
||||
|
||||
func IsInternal(err error) bool {
|
||||
return IsKind(err, KindInternal)
|
||||
}
|
||||
|
||||
func IsStore(err error) bool {
|
||||
return IsKind(err, KindStore)
|
||||
}
|
||||
|
||||
func IsObjStore(err error) bool {
|
||||
return IsKind(err, KindObjStore)
|
||||
}
|
||||
|
||||
func IsInvalidData(err error) bool {
|
||||
return IsKind(err, KindInvalidData)
|
||||
}
|
||||
|
||||
func IsNotFound(err error) bool {
|
||||
return IsKind(err, KindNotFound)
|
||||
}
|
||||
|
||||
func IsStaleData(err error) bool {
|
||||
return IsKind(err, KindStaleData)
|
||||
}
|
||||
|
||||
func IsDuplicateData(err error) bool {
|
||||
return IsKind(err, KindDuplicateData)
|
||||
}
|
||||
|
||||
func IsSensitiveData(err error) bool {
|
||||
return IsKind(err, KindSensitiveData)
|
||||
}
|
||||
|
||||
func IsUnauthorized(err error) bool {
|
||||
return IsKind(err, KindUnauthorized)
|
||||
}
|
||||
|
||||
func IsUnauthenticated(err error) bool {
|
||||
return IsKind(err, KindUnauthenticated)
|
||||
}
|
||||
|
||||
func IsExternal(err error) bool {
|
||||
return IsKind(err, KindExternal)
|
||||
}
|
||||
|
||||
func IsAutomation(err error) bool {
|
||||
return IsKind(err, KindAutomation)
|
||||
}
|
||||
Reference in New Issue
Block a user