From b21db848c4d741d1fd7b0ecdb78bd313ae9cc590 Mon Sep 17 00:00:00 2001 From: Sam Lown Date: Mon, 9 Dec 2024 09:55:52 +0000 Subject: [PATCH] Fix for gateway error matching --- internal/gateways/araba.go | 4 ++-- internal/gateways/ebizkaia.go | 6 +++--- internal/gateways/gateways.go | 4 ++-- internal/gateways/gipuzkoa.go | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/gateways/araba.go b/internal/gateways/araba.go index 3f769b6..346c26b 100644 --- a/internal/gateways/araba.go +++ b/internal/gateways/araba.go @@ -103,11 +103,11 @@ func (c *ArabaConn) post(ctx context.Context, path string, payload []byte) error return ErrConnection.withCause(err) } if res.StatusCode() != http.StatusOK { - return ErrInvalid.withCode(strconv.Itoa(res.StatusCode())) + return ErrValidation.withCode(strconv.Itoa(res.StatusCode())) } if out.Output.Status != arabaStatusReceived { - err := ErrInvalid + err := ErrValidation if len(out.Output.Errors) > 0 { e1 := out.Output.Errors[0] err = err.withMessage(e1.Description).withCode(e1.Code) diff --git a/internal/gateways/ebizkaia.go b/internal/gateways/ebizkaia.go index 1d2d90d..123eefd 100644 --- a/internal/gateways/ebizkaia.go +++ b/internal/gateways/ebizkaia.go @@ -86,13 +86,13 @@ func (c *EBizkaiaConn) Post(ctx context.Context, doc *doc.TicketBAI) error { resp := ebizkaia.LROEPJ240FacturasEmitidasConSGAltaRespuesta{} err = c.sendRequest(ctx, req, eBizkaiaExecutePath, &resp) - if errors.Is(err, ErrInvalid) { + if errors.Is(err, ErrValidation) { if resp.FirstErrorCode() == eBizkaiaN3RespCodeDuplicated { return ErrDuplicate } if resp.FirstErrorDescription() != "" { - return ErrInvalid.withCode(resp.FirstErrorCode()).withMessage(resp.FirstErrorDescription()) + return ErrValidation.withCode(resp.FirstErrorCode()).withMessage(resp.FirstErrorDescription()) } } @@ -178,7 +178,7 @@ func (c *EBizkaiaConn) sendRequest(ctx context.Context, doc *ebizkaia.Request, p if !slices.Contains(serverErrors, code) { // Not a server-side error, so the cause of it is in the request. We identify // it as an ErrInvalidRequest to handle it downstream. - return ErrInvalid.withCode(code).withMessage(msg) + return ErrValidation.withCode(code).withMessage(msg) } return ErrConnection.withCode(code).withMessage(msg) } diff --git a/internal/gateways/gateways.go b/internal/gateways/gateways.go index 7ee4cc3..a23d22c 100644 --- a/internal/gateways/gateways.go +++ b/internal/gateways/gateways.go @@ -26,10 +26,10 @@ const ( EnvironmentSandbox Environment = "sandbox" ) -// Standard gateway error responses +// Standard gateway error responses. Keys match the ones from main package. var ( ErrConnection = newError("connection") - ErrInvalid = newError("invalid") + ErrValidation = newError("validation") ErrDuplicate = newError("duplicate") ) diff --git a/internal/gateways/gipuzkoa.go b/internal/gateways/gipuzkoa.go index 9009532..a3c9b56 100644 --- a/internal/gateways/gipuzkoa.go +++ b/internal/gateways/gipuzkoa.go @@ -104,11 +104,11 @@ func (c *GipuzkoaConn) post(ctx context.Context, path string, payload []byte) er return ErrConnection.withCause(err) } if res.StatusCode() != http.StatusOK { - return ErrInvalid.withCode(strconv.Itoa(res.StatusCode())) + return ErrValidation.withCode(strconv.Itoa(res.StatusCode())) } if out.Output.Status != gipuzkoaStatusReceived { - err := ErrInvalid + err := ErrValidation if len(out.Output.Errors) > 0 { e1 := out.Output.Errors[0] err = err.withMessage(e1.Description).withCode(e1.Code)