added timeout error
This commit is contained in:
parent
9c96ccd888
commit
c32cb948d3
@ -22,6 +22,14 @@ func (err *ErrResourceNotFoundError) Error() string {
|
||||
return "resource not found"
|
||||
}
|
||||
|
||||
// ErrTimeout will be sent if the request took too long
|
||||
type ErrTimeout string
|
||||
|
||||
// Implement Error interface
|
||||
func (err ErrTimeout) Error() string {
|
||||
return string(err)
|
||||
}
|
||||
|
||||
// Variables
|
||||
var (
|
||||
ErrSourceNotFound = &ErrResourceNotFoundError{}
|
||||
@ -50,6 +58,7 @@ const (
|
||||
StatusError = http.StatusInternalServerError
|
||||
StatusResourceNotFound = http.StatusNotFound
|
||||
StatusValidationError = http.StatusBadRequest
|
||||
TimeoutError = http.StatusGatewayTimeout
|
||||
)
|
||||
|
||||
// Handle an error and create a error API response
|
||||
@ -63,6 +72,10 @@ func apiErrorResponse(
|
||||
status := StatusError
|
||||
|
||||
switch e := err.(type) {
|
||||
case ErrTimeout:
|
||||
tag = TagConnectionTimeout
|
||||
code = CodeConnectionTimeout
|
||||
status = TimeoutError
|
||||
case *ErrResourceNotFoundError:
|
||||
tag = TagResourceNotFound
|
||||
code = CodeResourceNotFound
|
||||
|
@ -48,7 +48,7 @@ func NewErrEmptyParam(key string) *ErrValidationFailed {
|
||||
|
||||
var (
|
||||
// ErrQueryTooShort will be returned when the query
|
||||
// is less than 2 characters.
|
||||
// is too short.
|
||||
ErrQueryTooShort = &ErrValidationFailed{
|
||||
"q", "the query is too short",
|
||||
}
|
||||
@ -106,10 +106,10 @@ func validatePrefixQuery(value string) (string, error) {
|
||||
// Helper: Validate neighbors query. A valid query should have
|
||||
// at least 4 chars.
|
||||
func validateNeighborsQuery(value string) (string, error) {
|
||||
if len(value) < 3 {
|
||||
// Maybe make configurable,
|
||||
// A length of 3 would be sufficient for "DFN" and
|
||||
// other shorthands.
|
||||
if len(value) < 4 {
|
||||
// TODO: Maybe make configurable
|
||||
// Three letters tend to result in queries with too
|
||||
// many results, which then leads to gateway timeouts.
|
||||
return "", ErrQueryTooShort
|
||||
}
|
||||
return value, nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user