Skip to content

Commit

Permalink
Fix for gateway error matching
Browse files Browse the repository at this point in the history
  • Loading branch information
samlown committed Dec 9, 2024
1 parent c6657cb commit b21db84
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions internal/gateways/araba.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions internal/gateways/ebizkaia.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/gateways/gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)

Expand Down
4 changes: 2 additions & 2 deletions internal/gateways/gipuzkoa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b21db84

Please sign in to comment.