I figured it out. SampleResult
has one more method called getResponseDataAsString()
. This method returns the response message. In case of error it contains the error message.
log stack trace when HTTP request return error in Jmeter
-
29-05-2022 - |
سؤال
I want to log all error message for failed HTTP request. I am going to run the thread group for 1B users and I don't want to use the View Result Tree because it logs everything and log file will bloat.
Currently I am using Beanshell Assertion as below.
if (Boolean.valueOf(vars.get("DEBUG"))) {
if (ResponseCode.equals("200") == false) {
log.info(SampleResult.getResponseMessage());
log.info("There was some problem");
}
}
But in this case it just prints the error message but I am interested to log the stack trace returned by the server.
I also used this method as mention in this thread
for (a: SampleResult.getAssertionResults()) {
if (a.isError() || a.isFailure()) {
log.error(Thread.currentThread().getName()+": "+SampleLabel+": Assertion failed for response: " + new String((byte[]) ResponseData));
}
}
But in this case I don't get an object out of SampleResult.getAssertionResults()
method and it doesn't display anything in case of HTTP request failure.
Any idea how to get the stacK trace?
المحلول
لا تنتمي إلى StackOverflow