Closed MrSent closed 5 years ago
That should be expected behaviour. Submitting the return should throw an TipsTrade.HMRC.Api.ApiException
for a duplicate submission (or for any errors that occur), so you should be catching that exception type first.
The ApiException has a property call ApiError
which contains the core error message as well as a list of more specific errors in the Errors
property.
Although, I'm a little surprised the message would be "Invalid request". When I try submitting a return with the ScenarioDuplicateSubmission scenario, the exception message is "Business validation error"
For example, I've just run added the following asserts to one of the tests (which succeed):
var request = new SubmitRequest() {
Return = CreateVatReturn(periodKey),
Vrn = Users.Organisation.User.Vrn,
GovTestScenario = SubmitRequest.ScenarioDuplicateSubmission
};
var ex = Assert.Throws<Api.ApiException>(() => client.Vat.SubmitReturn(request));
Assert.Equal("Business validation error", ex.Message);
Assert.Equal("BUSINESS_ERROR", ex.ApiError.Code);
Assert.Equal("Business validation error", ex.ApiError.Message);
Assert.Single(ex.ApiError.Errors);
Assert.Equal("DUPLICATE_SUBMISSION", ex.ApiError.Errors.First().Code);
Assert.Equal("The VAT return was already submitted for the given period.", ex.ApiError.Errors.First().Message);
So in your case you could do this:
try {
submitResponse = client.Vat.SubmitReturn(submitRequest);
// ...
} catch (ApiException ex) {
var detailedMessage = string.Join("\r\n", ex.ApiError.Errors.Select(x => x.Message));
}
Could you tell me the type of Exception that is being thrown?
I have just noticed I am not picking up the ApiException. I think I have just this second found it. The human readable error is "{amount should be a monetary value (to 2 decimal places), between 0 and 99,999,999,999.99}" so I would imagine my test data is not good. I'll have a further play about with it. In my haste I was picking up Exception ex rather than ApiException. My bad :)
And yes you were right. Duplicate submission gives Business validation error. Changing the scenario to Invalid Vrn give invalid request.
Yeah sorted now. Thanks again.
Yup, HMRC is very picky about the formatting - I had the exact same issue as I was submitting Decimal values to 4 places. Make sure you round any Decimal values to 2 places.
Now I've got a bit of time, I'll hopefully be adding some documentation to the README.
When posting a VAT return, I am trying to use the GovTestScenarios to try out set responses. I've posted into the Sandbox environment successfully but I need to try and simulate certain responses to check how my application reacts. I'm reading VAT returns from several sources which are placed into a folder where they are XML files. I read each individual one and then pull the data out and submit it. The code I have is here for the submit function. When I submit it I get a message back from the exception that just says "Invalid request". I've been through your test code to see what I'm doing differently, but I can't work it out.
` private void SubmitVATReturn(Client client, string psPath, Root pxMLVatReturn) { VatReturn vatReturn = new VatReturn(); SubmitRequest submitRequest = new SubmitRequest(); SubmitResponse submitResponse = new SubmitResponse();
` Have I misunderstood how the GovTestScenario settings work?