karatelabs / karate

Test Automation Made Simple

Home Page:https://karatelabs.github.io/karate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

karate.abort() response status == 500

knoxor opened this issue · comments

I am using the standalone jar to setup a mock server and I am looking to use schema validation to validate my request input and respond with a 400 error

e.g.

Background:
* def schema =
"""
{
name: '#string',
age: '#int'
}
"""

Scenario: pathMatches("/cat") && methodIs("post")
* def result = karate.match('request == schema')
* eval
"""
if (result.pass) {
responseStatus = 200;
} else {
responseStatus = 400;
karate.abort();
}
"""

But when the schema validation fails I get a http 500 error, how do I ensure I get a 4xx http status code ?

can't see anything wrong right away. hope someone else can help - is it possible for you to follow this process: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue

thanks for the quick response Peter.
I modified my code to use karate.set("responseStatus",400); before calling karate.abort() and that fixed my issue.
I'll follow the correct process if I have any other issues. Thanks

@knoxor no worries, glad it is sorted. if you are really going deep into mocks, please be aware that there is an alternative "more code" approach and there is a context.match() method for validations: https://github.com/karatelabs/karate/wiki/Karate-JavaScript-Mocks