Skip to content
Snippets Groups Projects
errors.go 3 KiB
Newer Older
  • Learn to ignore specific revisions
  • package apierrors
    
    // APIError is the base API error type.
    type APIError struct {
    	Success     bool   `json:"success"`
    	StatusCode  int    `json:"errorcode"`
    	Description string `json:"description"`
    
    	PolrStyle bool `json:"-"`
    }
    
    // Generic errors (Pomf style)
    var (
    	// BadToken is a 401 unauthorized error.
    	BadToken = APIError{false, 401, "bad token", false}
    
    	// Unauthorized is a 401 unauthorized error.
    	Unauthorized = APIError{false, 401, "unauthorized", false}
    
    	// InvalidJSONPayload is a 400 bad request error.
    	InvalidJSONPayload = APIError{false, 400, "invalid JSON payload", false}
    
    	// EmailOrUsernameNotSupplied is a 400 bad request error.
    	EmailOrUsernameNotSupplied = APIError{false, 400, "email or username not provided", false}
    
    	// InvalidEmailOrUsername is a 400 bad request error.
    	InvalidEmailOrUsername = APIError{false, 400, "invalid email or username", false}
    
    	// UserExists is a 409 conflict error.
    	UserExists = APIError{false, 409, "user with that email or username already exists", false}
    
    
    	// InvalidOffsetOrLimit is a 400 bad request error.
    	InvalidOffsetOrLimit = APIError{false, 400, "invalid offset or limit query paramters", false}
    
    	// OffsetTooLarge is a 400 bad request error.
    	OffsetTooLarge = APIError{false, 400, "offset is too big", false}
    
    	// NoObjectFound is a 404 not found error.
    	NoObjectFound = APIError{false, 404, "no object found", false}
    
    	// AlreadyDeleted is a 410 gone error.
    	AlreadyDeleted = APIError{false, 410, "already deleted", false}
    
    Dean's avatar
    Dean committed
    
    	// InsufficientTokens is a 429 too many requests error.
    	InsufficientTokens = APIError{false, 429, "too many requests", false}
    
    )
    
    // Pomf errors
    var (
    	// ContentLengthRequired is a 411 length required error.
    	ContentLengthRequired = APIError{false, 411, "Content-Length header required", false}
    
    	// InvalidContentLength is a 400 bad request error.
    	InvalidContentLength = APIError{false, 400, "invalid Content-Length header, should be an integer", false}
    
    	// BodyTooLarge is a 413 payload too large error.
    	BodyTooLarge = APIError{false, 413, "request body too large, DO NOT reattempt upload", false}
    
    	// NoFilesInRequest is a 400 bad request error.
    	NoFilesInRequest = APIError{false, 400, "no files[] present in multipart/form-data body", false}
    
    	// TooManyFilesInRequest a 400 bad request error.
    	TooManyFilesInRequest = APIError{false, 400, "too many files[] present in multipart/form-data body", false}
    
    	// InternalServerError is a 500 internal server error.
    	InternalServerError = APIError{false, 500, "internal server error", false}
    )
    
    // Polr errors
    var (
    	// UnauthorizedPolr is a 401 unauthorized error.
    	UnauthorizedPolr = APIError{false, 400, "unauthorized", true}
    
    	// InvalidPolrAction is a 400 bad request error.
    	InvalidPolrAction = APIError{false, 400, `invalid action, must be "shorten"`, true}
    
    	// InvalidPolrURL is a 400 bad request error.
    	InvalidPolrURL = APIError{false, 400, "invalid URL", true}
    
    	// InternalServerErrorPolr is a 500 internal server error.
    	InternalServerErrorPolr = APIError{false, 500, "internal server error", true}
    )