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

JsonReaderException in ThrowZendeskRequestException #330

Open
follesoe opened this issue Feb 5, 2024 · 3 comments
Open

JsonReaderException in ThrowZendeskRequestException #330

follesoe opened this issue Feb 5, 2024 · 3 comments

Comments

@follesoe
Copy link

follesoe commented Feb 5, 2024

It looks like there is an error in the code converting an error response from Zendesk into an exception.

It throws a JsonReaderException with the following message: Unexpected character encountered while parsing value: {. Path 'error', line 2, position 12..

I have not been able to capture the raw JSON to give an example of the error payload from Zendesk.

     Error sending message
      Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: {. Path 'error', line 2, position 12.
         at Newtonsoft.Json.JsonTextReader.ReadStringValue(ReadType readType)
         at Newtonsoft.Json.JsonTextReader.ReadAsString()
         at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
         at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
         at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
         at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
         at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
         at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
         at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
         at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader reader)
         at ZendeskApi.Client.Extensions.HttpContentExtensions.ReadAs[T](Stream stream)
         at ZendeskApi.Client.Extensions.HttpContentExtensions.ReadAsAsync[T](HttpContent content)
         at ZendeskApi.Client.Exceptions.ZendeskRequestExceptionBuilder.Build()
         at ZendeskApi.Client.Extensions.HttpResponseExtensions.ThrowZendeskRequestException(HttpResponseMessage response, String helpDocLink, HttpStatusCode[] expected, String helpDocLinkPrefix)
         at ZendeskApi.Client.Extensions.HttpResponseExtensions.ThrowZendeskRequestException(HttpResponseMessage response, String helpDocLink, Nullable`1 expected, String helpDocLinkPrefix)
         at ZendeskApi.Client.Extensions.HttpResponseExtensions.ThrowIfUnsuccessful(Task`1 response, String helpDocLink, Nullable`1 expected, String helpDocLinkPrefix)
         at ZendeskApi.Client.Resources.AbstractBaseResource`1.CreateAsync[TRequest](String resource, TRequest item, String docs, HttpStatusCode expectedStatusCode, String scope, CancellationToken cancellationToken)
         at ZendeskApi.Client.Extensions.HttpResponseExtensions.ReadContentAsAsync[T](Task`1 response, JsonConverter converter)
         at ZendeskApi.Client.Resources.AbstractBaseResource`1.CreateAsync[TResponse,TRequest](String resource, TRequest item, String docs, HttpStatusCode expectedStatusCode, String scope, CancellationToken cancellationToken)
         at ZendeskApi.Client.Resources.TicketsResource.CreateAsync(TicketCreateRequest ticket, CancellationToken cancellationToken)
@fbvilela
Copy link
Contributor

Hi @follesoe, what are the steps to reproduce? what are the ticket arguments you passed in when trying to create?

@follesoe
Copy link
Author

@fbvilela I believe it was due to an incorrect auth token. So I would try it out by setting an invalid token and see how the ZendeskRequestExceptionBuilder behaves.

@adamkerik-rr
Copy link

The JSON body I am receiving when this error occurs is:

{ "error": { "title": "Forbidden", "message": "You do not have access to this page. Please contact the account owner of this help desk for further help." } }

MatthewBAllen added a commit to MatthewBAllen/ZendeskApiClient that referenced this issue Aug 30, 2024
…or with object body

We received two different error message formats.

one:
{
    "error": "Couldn't authenticate you"
}

two:
{
    "error": {
        "title": "Forbidden",
        "message": "You do not have access to this page. Please contact the account owner of this help desk for further help."
    }
}

The current ErrorResponse model class was able to handle the first response but would throw this error with the second response: "Unexpected character encountered while parsing value: {. Path 'error', line 2, position 12" because it's expecting a string value for error but instead it hits a complex object . The new ErrorWithMessageResponse model class will allow the user to deserialize the second response and convert it to an ErrorResponse object.
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

3 participants