Skip to content

Commit

Permalink
Improve service unavailable reporting (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisrollins65 authored Aug 6, 2024
1 parent 0225b8a commit 3343a36
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions vies_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vat
import (
"bytes"
"encoding/xml"
"errors"
"io"
"net/http"
"strings"
Expand Down Expand Up @@ -41,9 +42,10 @@ func (s *viesService) Validate(vatNumber string) error {
}

// check if response contains "MS_UNAVAILABLE" string
if bytes.Contains(xmlRes, []byte("MS_UNAVAILABLE")) ||
bytes.Contains(xmlRes, []byte("MS_MAX_CONCURRENT_REQ")) {
return ErrServiceUnavailable{Err: nil}
if bytes.Contains(xmlRes, []byte("MS_UNAVAILABLE")) {
return ErrServiceUnavailable{Err: errors.New("vies reports service is unavailable")}
} else if bytes.Contains(xmlRes, []byte("MS_MAX_CONCURRENT_REQ")) {
return ErrServiceUnavailable{Err: errors.New("max concurrent requests limit hit")}
}

var rd struct {
Expand Down

0 comments on commit 3343a36

Please sign in to comment.