ddeboer / vatin

Validate VAT identification numbers
MIT License
136 stars 37 forks source link

Improvement: make checkVat() exception message more accurate #38

Open dzschille opened 3 years ago

dzschille commented 3 years ago

Currently the method checkVat() just throws a ViesException with the message: 'Error communicating with VIES service'. Bit it is possible to give a more accurate message back. This is from the documentation of the https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl :

In case of problems, the returned FaultString can take the following specific values:

  • INVALID_INPUT: The provided CountryCode is invalid or the VAT number is empty;

  • GLOBAL_MAX_CONCURRENT_REQ: Your Request for VAT validation has not been processed; the maximum number of concurrent requests has been reached. Please re-submit your request later or contact TAXUD-VIESWEB@ec.europa.eu for further information": Your request cannot be processed due to high traffic on the web application. Please try again later;

  • MS_MAX_CONCURRENT_REQ: Your Request for VAT validation has not been processed; the maximum number of concurrent requests for this Member State has been reached. Please re-submit your request later or contact TAXUD-VIESWEB@ec.europa.eu for further information": Your request cannot be processed due to high traffic towards the Member State you are trying to reach. Please try again later.

  • SERVICE_UNAVAILABLE: an error was encountered either at the network level or the Web application level, try again later;

  • MS_UNAVAILABLE: The application at the Member State is not replying or not available. Please refer to the Technical Information page to check the status of the requested Member State, try again later;

  • TIMEOUT: The application did not receive a reply within the allocated time period, try again later.

It would be helpful to know why the check failed. Was it because of a wrong VAT number or a failed request? What do you think about throwing different exceptions or the ViesException with different messages? We could group it like

ddeboer commented 3 years ago

Good suggestion! Please feel free to make the change and open a PR.