Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return too_many_requests for MS_MAX_CONCURRENT_REQ error #4

Merged
merged 3 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
import Config

# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
Expand Down
31 changes: 31 additions & 0 deletions fixture/vcr_cassettes/lookup_requests_limit_reached.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[
{
"request": {
"body": "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:ec.europa.eu:taxud:vies:services:checkVat:types\">\n <soapenv:Header/>\n <soapenv:Body>\n <urn:checkVat>\n <urn:countryCode>NL</urn:countryCode>\n <urn:vatNumber>9999999</urn:vatNumber>\n </urn:checkVat>\n </soapenv:Body>\n </soapenv:Envelope>",
"headers": {
"SOAPAction": "",
"Content-Type": "text/xml;charset=UTF-8"
},
"method": "post",
"options": [],
"request_body": "",
"url": "http://ec.europa.eu/taxation_customs/vies/services/checkVatService"
},
"response": {
"binary": false,
"body": "<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"><env:Header/><env:Body><env:Fault><faultcode>env:Server</faultcode><faultstring>MS_MAX_CONCURRENT_REQ</faultstring></env:Fault></env:Body></env:Envelope>",
"headers": {
"Date": "Fri, 11 Aug 2023 11:23:11 GMT",
"Content-Length": "221",
"Content-Type": "text/xml; charset=UTF-8",
"SOAPAction": "\"\"",
"Accept": "text/xml",
"Server": "Europa",
"Proxy-Connection": "Keep-Alive",
"Connection": "keep-alive"
},
"status_code": 200,
"type": "ok"
}
}
]
8 changes: 6 additions & 2 deletions lib/viex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ defmodule Viex do
defp handle_soap_response({:ok, %HTTPoison.Response{status_code: 500}}),
do: {:error, :internal_server_error}

defp handle_soap_response({:ok, %HTTPoison.Response{status_code: 200, body: body}}),
do: {:ok, body}
defp handle_soap_response({:ok, %HTTPoison.Response{status_code: 200, body: body}}) do
cond do
String.contains?(body, "MS_MAX_CONCURRENT_REQ") -> {:error, :too_many_requests}
true -> {:ok, body}
end
end

defp headers() do
[
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Viex.Mixfile do
def project do
[
app: :viex,
version: "0.3.1",
version: "0.3.2",
elixir: "~> 1.4",
description: "Elixir package to validate European VAT numbers with the VIES service.",
build_embedded: Mix.env() == :prod,
Expand Down
8 changes: 8 additions & 0 deletions test/viex_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ defmodule ViexTest do
end
end

test "lookup with requests limit reached" do
use_cassette "lookup_requests_limit_reached" do
response = Viex.lookup("NL9999999")

assert response == {:error, :too_many_requests}
end
end

test "valid?" do
use_cassette "valid" do
assert Viex.valid?("NL854265259B01") == true
Expand Down
Loading