mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
currently: * container ran out of memory (code 137) * container exited with other code != 0 * unable to pull image (auth/404) there may be others but this is a good start (the most common). notably, for both hot and cold these should bubble up (if deterministic, which hub isn't always), and these are useful for users to use in debugging why things aren't working. added tests to make sure that these behaviors are working. also changed the behavior such that when the container exits we return a 502 instead of a 503, just to be able to distinguish the fact that fn is working as expected but the container is acting funky (400 is weird here, so idk). removed references to old IsUserVisible crap and slightly changed the interface for RunResult for plumbing reasons (to get the error type, specifically). fixed an issue where if ~/.docker/config.json exists sometimes pulling images wouldn't work deterministically (should be more inline w/ expectations now) closes #275
181 lines
4.4 KiB
Go
181 lines
4.4 KiB
Go
package models
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
// TODO we can put constants all in this file too
|
|
const (
|
|
maxAppName = 30
|
|
)
|
|
|
|
var (
|
|
ErrInvalidJSON = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Invalid JSON"),
|
|
}
|
|
ErrCallTimeout = err{
|
|
code: http.StatusGatewayTimeout,
|
|
error: errors.New("Timed out"),
|
|
}
|
|
ErrAppsValidationMissingName = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Missing app name"),
|
|
}
|
|
ErrAppsValidationTooLongName = err{
|
|
code: http.StatusBadRequest,
|
|
error: fmt.Errorf("App name must be %v characters or less", maxAppName),
|
|
}
|
|
ErrAppsValidationInvalidName = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Invalid app name"),
|
|
}
|
|
ErrAppsAlreadyExists = err{
|
|
code: http.StatusConflict,
|
|
error: errors.New("App already exists"),
|
|
}
|
|
ErrAppsMissingNew = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Missing new application"),
|
|
}
|
|
ErrAppsNameImmutable = err{
|
|
code: http.StatusConflict,
|
|
error: errors.New("Could not update app - name is immutable"),
|
|
}
|
|
ErrAppsNotFound = err{
|
|
code: http.StatusNotFound,
|
|
error: errors.New("App not found"),
|
|
}
|
|
ErrDeleteAppsWithRoutes = err{
|
|
code: http.StatusConflict,
|
|
error: errors.New("Cannot remove apps with routes"),
|
|
}
|
|
ErrDatastoreEmptyAppName = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Missing app name"),
|
|
}
|
|
ErrDatastoreEmptyRoutePath = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Missing route name"),
|
|
}
|
|
ErrDatastoreEmptyApp = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Missing app"),
|
|
}
|
|
ErrDatastoreEmptyRoute = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Missing route"),
|
|
}
|
|
ErrDatastoreEmptyKey = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Missing key"),
|
|
}
|
|
ErrDatastoreEmptyCallID = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Missing call ID"),
|
|
}
|
|
ErrInvalidPayload = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Invalid payload"),
|
|
}
|
|
ErrRoutesAlreadyExists = err{
|
|
code: http.StatusConflict,
|
|
error: errors.New("Route already exists"),
|
|
}
|
|
ErrRoutesMissingNew = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Missing new route"),
|
|
}
|
|
ErrRoutesNotFound = err{
|
|
code: http.StatusNotFound,
|
|
error: errors.New("Route not found"),
|
|
}
|
|
ErrRoutesPathImmutable = err{
|
|
code: http.StatusConflict,
|
|
error: errors.New("Could not update route - path is immutable"),
|
|
}
|
|
ErrRoutesValidationFoundDynamicURL = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Dynamic URL is not allowed"),
|
|
}
|
|
ErrRoutesValidationInvalidPath = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Invalid Path format"),
|
|
}
|
|
ErrRoutesValidationInvalidType = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Invalid route Type"),
|
|
}
|
|
ErrRoutesValidationInvalidFormat = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Invalid route Format"),
|
|
}
|
|
ErrRoutesValidationMissingAppName = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Missing route AppName"),
|
|
}
|
|
ErrRoutesValidationMissingImage = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Missing route Image"),
|
|
}
|
|
ErrRoutesValidationMissingName = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Missing route Name"),
|
|
}
|
|
ErrRoutesValidationMissingPath = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Missing route Path"),
|
|
}
|
|
ErrRoutesValidationMissingType = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Missing route Type"),
|
|
}
|
|
ErrRoutesValidationPathMalformed = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Path malformed"),
|
|
}
|
|
ErrRoutesValidationNegativeTimeout = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Negative timeout"),
|
|
}
|
|
ErrRoutesValidationNegativeIdleTimeout = err{
|
|
code: http.StatusBadRequest,
|
|
error: errors.New("Negative idle timeout"),
|
|
}
|
|
ErrCallNotFound = err{
|
|
code: http.StatusNotFound,
|
|
error: errors.New("Call not found"),
|
|
}
|
|
ErrCallLogNotFound = err{
|
|
code: http.StatusNotFound,
|
|
error: errors.New("Call log not found"),
|
|
}
|
|
)
|
|
|
|
// any error that implements this interface will return an API response
|
|
// with the provided status code and error message body
|
|
type APIError interface {
|
|
Code() int
|
|
error
|
|
}
|
|
|
|
type err struct {
|
|
code int
|
|
error
|
|
}
|
|
|
|
func (e err) Code() int { return e.code }
|
|
|
|
func NewAPIError(code int, e error) APIError { return err{code, e} }
|
|
|
|
// uniform error output
|
|
type Error struct {
|
|
Error *ErrorBody `json:"error,omitempty"`
|
|
}
|
|
|
|
func (m *Error) Validate() error {
|
|
return nil
|
|
}
|