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

Notify Client Exception is not a standard json object #161

Open
ghost opened this issue May 30, 2022 · 1 comment
Open

Notify Client Exception is not a standard json object #161

ghost opened this issue May 30, 2022 · 1 comment

Comments

@ghost
Copy link

ghost commented May 30, 2022

private void HandleHTTPErrors(HttpResponseMessage response, string errorResponseContent)
{
try
{
var errorResponse = JsonConvert.DeserializeObject<NotifyHTTPErrorResponse>(errorResponseContent);
throw new NotifyClientException("Status code {0}. The following errors occured {1}", errorResponse.getStatusCode(), errorResponse.getErrorsAsJson());
}
catch (Exception ex)
{
throw new NotifyClientException("Status code {0}. Error: {1}, Exception: {2}", response.StatusCode.GetHashCode(), errorResponseContent, ex.Message);
}
}

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
Copy link

gbishton commented Nov 1, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant