Skip to content

Commit

Permalink
Add error code to be treated as a server error
Browse files Browse the repository at this point in the history
  • Loading branch information
cavalle committed Mar 26, 2024
1 parent efa9924 commit 04a13de
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions internal/gateways/ebizkaia.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/tls"
"errors"
"fmt"
"slices"

"github.com/go-resty/resty/v2"
"github.com/invopop/gobl.ticketbai/internal/doc"
Expand All @@ -29,12 +30,20 @@ const (
eBizkaiaN3ResponseHeader = "Eus-Bizkaia-N3-Tipo-Respuesta"
eBizkaiaN3RespCodeHeader = "Eus-Bizkaia-N3-Codigo-Respuesta"
eBizkaiaN3RegNumberHeader = "Eus-Bizkaia-N3-Numero-Registro"
eBizkaiaN3ResponseInvalid = "Incorrecto"

eBizkaiaN3ResponseInvalid = "Incorrecto"
eBizkaiaN3RespCodeTechnical = "B4_1000004"
eBizkaiaN3RespCodeDuplicated = "B4_2000003"
// Response codes of interest
eBizkaiaN3RespCodeTechnical = "B4_1000004" // “Error técnico”
eBizkaiaN3RespCodeDuplicated = "B4_2000003" // “El registro no puede existir en el sistema”
eBizkaiaN3RespCodeOther = "N3_0000011" // “Otros, consulte el mensaje recibido como respuesta a la petición o con el responsable de la aplicación”

Check failure on line 38 in internal/gateways/ebizkaia.go

View workflow job for this annotation

GitHub Actions / golangci-lint

`responsable` is a misspelling of `responsible` (misspell)
)

// Server-side error codes
var serverErrors = []string{
eBizkaiaN3RespCodeTechnical,
eBizkaiaN3RespCodeOther,
}

// EBizkaiaConn keeps all the connection details together for the Vizcaya region.
type EBizkaiaConn struct {
client *resty.Client
Expand Down Expand Up @@ -170,9 +179,9 @@ func (c *EBizkaiaConn) sendRequest(ctx context.Context, doc *ebizkaia.Request, p
msg = convertToUTF8(msg)

code := res.Header().Get(eBizkaiaN3RespCodeHeader)
if code != eBizkaiaN3RespCodeTechnical {
// Not a technical error, so the cause of it is in the request. We identify
// it as an ErrInvalidRequest to handle it properly later.
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 fmt.Errorf("ebizcaia: %w: %v: %v", ErrInvalidRequest, code, msg)
}

Expand Down

0 comments on commit 04a13de

Please sign in to comment.