zeus1234
zeus1234

Reputation: 473

Karate API: JSON parsing error shown instead of wrong HTTP code returned

Given have the following list of steps

Given path 'verify'
And header x-api-key = apiKey
And header tenant-id = tenantId
And request a_json_object_with_invalid_user_id_to_verify
When method put
Then status 404

When the endpoint returned HTTP 200 (which is a bug that i need to fix) but with an invalid json response such as

{
  "score" : 
}

This exception is thrown

com.jayway.jsonpath.InvalidJsonException: net.minidev.json.parser.ParseException: Unexpected character (}) at position 15.
    at com.jayway.jsonpath.spi.json.JsonSmartJsonProvider.parse(JsonSmartJsonProvider.java:64)
    at com.jayway.jsonpath.internal.JsonContext.parse(JsonContext.java:82)
    at com.jayway.jsonpath.JsonPath.parse(JsonPath.java:596)
    at com.intuit.karate.JsonUtils.toJsonDoc(JsonUtils.java:84)
    at com.intuit.karate.StepDefs.method(StepDefs.java:344)

I expect to see the test failed because of wrong status code 200 received of the expected 404. I would like to know if throwing this exception is correct in karate?

Thanks.

Upvotes: 1

Views: 1839

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

I apologize for mis-reading your question.

There is indeed a bug in Karate when handling malformed JSON responses.

We have opened an issue, you should be able to get a patch version very soon: https://github.com/intuit/karate/issues/259

Upvotes: 1

Related Questions