mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* Manage configuration of polling period in connectors manager and enable override via env variables * Treat connector validation errors as http 4xx * Perform strict config validation only if connector being loaded for install or update * Add flags to configure notification outbox schedules * Only configure outbox schedule creation in worker * Improve manager config validation test coverage
47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
package v2
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/formancehq/payments/internal/connectors"
|
|
"github.com/formancehq/payments/internal/connectors/engine"
|
|
|
|
"github.com/formancehq/go-libs/v3/api"
|
|
"github.com/formancehq/payments/internal/api/common"
|
|
"github.com/formancehq/payments/internal/api/services"
|
|
"github.com/formancehq/payments/internal/storage"
|
|
errorsutils "github.com/formancehq/payments/internal/utils/errors"
|
|
)
|
|
|
|
const (
|
|
ErrUniqueReference = "CONFLICT"
|
|
ErrNotFound = "NOT_FOUND"
|
|
ErrInvalidID = "INVALID_ID"
|
|
ErrMissingOrInvalidBody = "MISSING_OR_INVALID_BODY"
|
|
ErrValidation = "VALIDATION"
|
|
ErrConnectorCapabilityNotSupported = "CONNECTOR_CAPABILITY_NOT_SUPPORTED"
|
|
)
|
|
|
|
func handleServiceErrors(w http.ResponseWriter, r *http.Request, err error) {
|
|
var capabilityNotSupported *engine.ErrConnectorCapabilityNotSupported
|
|
|
|
switch {
|
|
case errors.Is(err, storage.ErrDuplicateKeyValue):
|
|
api.BadRequest(w, ErrUniqueReference, err)
|
|
case errors.Is(err, storage.ErrNotFound):
|
|
api.NotFound(w, err)
|
|
case errors.Is(err, storage.ErrValidation):
|
|
api.BadRequest(w, ErrValidation, err)
|
|
case errors.Is(err, services.ErrValidation), errors.Is(err, connectors.ErrValidation):
|
|
cause := errorsutils.Cause(err)
|
|
api.BadRequest(w, ErrValidation, cause)
|
|
case errors.Is(err, services.ErrNotFound):
|
|
api.NotFound(w, err)
|
|
case errors.As(err, &capabilityNotSupported):
|
|
api.BadRequest(w, ErrConnectorCapabilityNotSupported, err)
|
|
default:
|
|
common.InternalServerError(w, r, err)
|
|
}
|
|
}
|