2019-05-01 11:44:45 +00:00
|
|
|
package api
|
|
|
|
|
2020-04-04 14:03:50 +00:00
|
|
|
import "net/http"
|
|
|
|
|
2019-05-01 11:44:45 +00:00
|
|
|
var (
|
2021-03-28 16:49:23 +00:00
|
|
|
// ErrUnknown represents any error which cause is unknown.
|
2019-05-01 11:44:45 +00:00
|
|
|
// It might also be used for debug purposes as this error
|
|
|
|
// has to be used the less possible
|
2021-03-28 16:49:23 +00:00
|
|
|
ErrUnknown = Err{-1, "unknown error", http.StatusOK}
|
2020-03-28 13:51:49 +00:00
|
|
|
|
2021-03-28 16:49:23 +00:00
|
|
|
// ErrSuccess represents a generic successful service execution
|
|
|
|
ErrSuccess = Err{0, "all right", http.StatusOK}
|
2020-03-28 13:51:49 +00:00
|
|
|
|
2021-03-28 16:49:23 +00:00
|
|
|
// ErrFailure is the most generic error
|
|
|
|
ErrFailure = Err{1, "it failed", http.StatusInternalServerError}
|
2019-05-01 11:44:45 +00:00
|
|
|
|
2021-03-28 16:49:23 +00:00
|
|
|
// ErrNoMatchFound is set when trying to fetch data and there is no result
|
|
|
|
ErrNoMatchFound = Err{2, "resource not found", http.StatusOK}
|
2019-05-01 11:44:45 +00:00
|
|
|
|
2021-03-28 16:49:23 +00:00
|
|
|
// ErrAlreadyExists is set when trying to insert data, but identifiers or
|
2019-05-01 11:44:45 +00:00
|
|
|
// unique fields already exists
|
2021-03-28 16:49:23 +00:00
|
|
|
ErrAlreadyExists = Err{3, "already exists", http.StatusOK}
|
2019-05-01 11:44:45 +00:00
|
|
|
|
2021-03-28 16:49:23 +00:00
|
|
|
// ErrCreation is set when there is a creation/insert error
|
|
|
|
ErrCreation = Err{4, "create error", http.StatusOK}
|
2020-04-04 08:08:11 +00:00
|
|
|
|
2021-03-28 16:49:23 +00:00
|
|
|
// ErrModification is set when there is an update/modification error
|
|
|
|
ErrModification = Err{5, "update error", http.StatusOK}
|
2020-04-04 08:08:11 +00:00
|
|
|
|
2021-03-28 16:49:23 +00:00
|
|
|
// ErrDeletion is set when there is a deletion/removal error
|
|
|
|
ErrDeletion = Err{6, "delete error", http.StatusOK}
|
2020-04-04 08:08:11 +00:00
|
|
|
|
2021-03-28 16:49:23 +00:00
|
|
|
// ErrTransaction is set when there is a transactional error
|
|
|
|
ErrTransaction = Err{7, "transactional error", http.StatusOK}
|
2020-04-04 08:08:11 +00:00
|
|
|
|
2021-03-28 16:49:23 +00:00
|
|
|
// ErrUpload is set when a file upload failed
|
|
|
|
ErrUpload = Err{100, "upload failed", http.StatusInternalServerError}
|
2019-05-01 11:44:45 +00:00
|
|
|
|
2021-03-28 16:49:23 +00:00
|
|
|
// ErrDownload is set when a file download failed
|
|
|
|
ErrDownload = Err{101, "download failed", http.StatusInternalServerError}
|
2019-05-01 11:44:45 +00:00
|
|
|
|
2021-03-28 16:49:23 +00:00
|
|
|
// MissingDownloadHeaders is set when the implementation
|
2019-05-02 05:54:45 +00:00
|
|
|
// of a service of type 'download' (which returns a file instead of
|
2019-05-01 11:44:45 +00:00
|
|
|
// a set or output fields) is missing its HEADER field
|
2021-03-28 16:49:23 +00:00
|
|
|
MissingDownloadHeaders = Err{102, "download headers are missing", http.StatusBadRequest}
|
2019-05-01 11:44:45 +00:00
|
|
|
|
2021-03-28 16:49:23 +00:00
|
|
|
// ErrMissingDownloadBody is set when the implementation
|
2019-05-02 05:54:45 +00:00
|
|
|
// of a service of type 'download' (which returns a file instead of
|
2019-05-01 11:44:45 +00:00
|
|
|
// a set or output fields) is missing its BODY field
|
2021-03-28 16:49:23 +00:00
|
|
|
ErrMissingDownloadBody = Err{103, "download body is missing", http.StatusBadRequest}
|
2019-05-01 11:44:45 +00:00
|
|
|
|
2021-03-28 16:49:23 +00:00
|
|
|
// ErrUnknownService is set when there is no service matching
|
2019-05-01 11:44:45 +00:00
|
|
|
// the http request URI.
|
2021-03-28 16:49:23 +00:00
|
|
|
ErrUnknownService = Err{200, "unknown service", http.StatusServiceUnavailable}
|
2019-05-01 11:44:45 +00:00
|
|
|
|
2021-03-28 16:49:23 +00:00
|
|
|
// ErrUncallableService is set when there the requested service's
|
2019-05-01 11:44:45 +00:00
|
|
|
// implementation (plugin file) is not found/callable
|
2021-03-28 16:49:23 +00:00
|
|
|
ErrUncallableService = Err{202, "uncallable service", http.StatusServiceUnavailable}
|
2020-03-28 13:51:49 +00:00
|
|
|
|
2021-03-28 16:49:23 +00:00
|
|
|
// ErrNotImplemented is set when a handler is not implemented yet
|
|
|
|
ErrNotImplemented = Err{203, "not implemented", http.StatusNotImplemented}
|
2019-05-01 11:44:45 +00:00
|
|
|
|
2021-03-28 16:49:23 +00:00
|
|
|
// ErrPermission is set when there is a permission error by default
|
2019-05-01 11:44:45 +00:00
|
|
|
// the api returns a permission error when the current scope (built
|
|
|
|
// by middlewares) does not match the scope required in the config.
|
|
|
|
// You can add your own permission policy and use this error
|
2021-03-28 16:49:23 +00:00
|
|
|
ErrPermission = Err{300, "permission error", http.StatusUnauthorized}
|
2019-05-01 11:44:45 +00:00
|
|
|
|
2021-03-28 16:49:23 +00:00
|
|
|
// ErrToken is set (usually in authentication middleware) to tell
|
2019-05-01 11:44:45 +00:00
|
|
|
// the user that this authentication token is expired or invalid
|
2021-03-28 16:49:23 +00:00
|
|
|
ErrToken = Err{301, "token error", http.StatusForbidden}
|
2019-05-01 11:44:45 +00:00
|
|
|
|
2021-03-28 16:49:23 +00:00
|
|
|
// ErrMissingParam is set when a *required* parameter is missing from the
|
2019-05-01 11:44:45 +00:00
|
|
|
// http request
|
2021-03-28 16:49:23 +00:00
|
|
|
ErrMissingParam = Err{400, "missing parameter", http.StatusBadRequest}
|
2019-05-01 11:44:45 +00:00
|
|
|
|
2021-03-28 16:49:23 +00:00
|
|
|
// ErrInvalidParam is set when a given parameter fails its type check as
|
2019-05-01 11:44:45 +00:00
|
|
|
// defined in the config file.
|
2021-03-28 16:49:23 +00:00
|
|
|
ErrInvalidParam = Err{401, "invalid parameter", http.StatusBadRequest}
|
2019-05-01 11:44:45 +00:00
|
|
|
|
2021-03-28 16:49:23 +00:00
|
|
|
// ErrInvalidDefaultParam is set when an optional parameter's default value
|
2019-05-01 11:44:45 +00:00
|
|
|
// does not match its type.
|
2021-03-28 16:49:23 +00:00
|
|
|
ErrInvalidDefaultParam = Err{402, "invalid default param", http.StatusBadRequest}
|
2019-05-01 11:44:45 +00:00
|
|
|
)
|