alphagov / notifications-net-client

.NET client for the GOV.UK Notify API
https://www.nuget.org/packages/GovukNotify/
MIT License
25 stars 20 forks source link

Notify Client Exception is not a standard json object #161

Open ghost opened 2 years ago

ghost commented 2 years ago

https://github.com/alphagov/notifications-net-client/blob/358238c2f5a1c466c7704d8ac0749bc9dd2b1ce3/src/GovukNotify/Client/BaseClient.cs#L118-L129

When an exception occurs, a NotifyClientException is thrown, but its content is a plain string as outlined above. The string contains the information from the documentation, but in a very unintuitive way, making it difficult to parse. For example, here is the string from the 'message' field one one such case:

Status code 400. Error: {"errors":[{"error":"ValidationError","message":"email_address Not a valid email address"}],"status_code":400}, Exception: Status code 400. The following errors occured [{"error": "ValidationError", "message": "email_address Not a valid email address"}]

I would much rather work with just the following, since it is much easier to parse, or maybe even incorporate those as fields in the NotifyClientException class.: {"errors":[{"error":"ValidationError","message":"email_address Not a valid email address"}],"status_code":400}

gbishton commented 2 years ago

I agree the string returned is difficult to parse and would prefer the JSON result suggested.