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

Get response status message #2591

Open
leandrofrs opened this issue Aug 1, 2024 · 1 comment
Open

Get response status message #2591

leandrofrs opened this issue Aug 1, 2024 · 1 comment

Comments

@leandrofrs
Copy link

leandrofrs commented Aug 1, 2024

The current implementation of karate only returns the status as an int by implementing the method getStatusCode(), as described in the following documentation:

https://javadoc.jetbrains.net/teamcity/openapi/current/jetbrains/buildServer/util/HTTPRequestBuilder.Response.html

image

Is there any way to return the status message (by implementing the method getStatusText() to Karate) that comes with the status code? Like 400 = Bad Request, 200 = OK

The given problem is that I've an API that has different status messages for the code 400. I want to differentiate my test cases based on the message that comes with the code.

@ptrthomas
Copy link
Member

@leandrofrs yes karate does not give you the status text and interestingly for the last 7 years no one has needed it :)

for contributor reference, I think the line to look at is this: https://github.com/karatelabs/karate/blob/master/karate-core/src/main/java/com/intuit/karate/http/ApacheHttpClient.java#L309

and it seems you can call httpResponse.getStatusLine().getReasonPhrase().

in the meantime, I was seeing if you can fallback to curl using this approach: https://stackoverflow.com/a/64352676/143475 - I tried to do some digging if curl can get you the status message, but gave up.

you always have the option of writing some java code that fires up an apache http client and using it via java interop. personally I think these tests for a 400 are not worth it, but if really important - this java interop option is what I would recommend

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

No branches or pull requests

2 participants