# Handling Error Messages of JMeter Tests in Loadium old

Errors found during [testing](https://loadium.com/blog/functional-testing-with-loadium-apache-jmeter/) is a part of the process, [tests](https://loadium.com/blog/record-and-play-load-testing-in-5-steps/) are done to find them after all. After finding an error, understanding its reason is crucial. Some errors are easy to understand and recognize if they reveal themselves clearly, but sometimes errors are hard to detect and if their reason isn’t clear it might even lead to more confusing results.

There might be several reasons for an error to occur. It could be due to a logical error in the script, or while the script is doing its work properly, server might mess up when processing it.

## Jmeter Functions

[JMeter](https://loadium.com/blog/how-to-add-a-variable-number-of-parameters-in-apache-jmeter/) has a built-in functionality that allows us to handle error messages. Since [JMeter](https://loadium.com/blog/in-depth-analysis-throughput-controller-in-jmeter-and-splitting-threads-to-requests/) is a Java application which is an OOP language, there is access to some objects that come in handy. One of them is the “Prev” class’ “prev” object that allows us to do workarounds for error messages, which you can find the complete documentation here:

<https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html>

Let’s take a look at some methods from this class:

* getResponseCode() – Returns the last executed sample’s response code
* setResponseCode() – Sets a custom response code to the last executed sample
* getResponseDataAsString() – Returns the last executed sample’s response body

By using only these 3 methods, we can easily handle the error messages.

## Example Case

Sometimes the message contained in the response code or the code itself isn’t self-explanatory enough. Likewise, there may be more detailed information of the error in the response body, and since what’s included in the body by default is not available to be seen in the report screen “Error” page, a configuration can be done to make it visible.

For example, the response error message “Internal Server Error” does not show the reason clearly, and if there is a possibility that its body contains information about the error, it is better for it to be shown here. For this, we can make a configuration in a JSR223 PostProcessor like the following:

![](https://33973752-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUOy4kHWrKkuqX5mhH7%2F-Mchg7XuMHNJ5TK2SfZW%2F-Mci8YzdU7Lyy3uxWYkV%2FScreen%20Shot%202021-06-21%20at%2013.38.07.png?alt=media\&token=da296404-629b-4c0f-bd46-6d0e4792dbe5)

And with the function:

`if(prev.getResponseCode() == "500"){`\
`prev.setResponseMessage(prev.getResponseDataAsString());`

In Jmeter, instead of standart "Internal Server Error" message, we will get a message as shown below:

![](https://33973752-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUOy4kHWrKkuqX5mhH7%2F-Mchg7XuMHNJ5TK2SfZW%2F-Mci9UNWutLHtkRWGlVF%2Fresponsecode.png?alt=media\&token=88b50ded-f4e6-4bcc-81b4-90dad882bb59)

While in Loadium Report Screen, we will get the following result in Response Codes Page or Errors Page:

![](https://33973752-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUOy4kHWrKkuqX5mhH7%2F-Mchg7XuMHNJ5TK2SfZW%2F-Mci8pK3yxj7hrtKvg5M%2FScreen%20Shot%202021-06-21%20at%2013.33.41.png?alt=media\&token=d7393257-e50e-4be3-96e6-a0b8f84ce10e)

Happy testing!

{% content-ref url="../create-test/jmeter-test" %}
[jmeter-test](https://wiki.loadium.com/create-test/jmeter-test)
{% endcontent-ref %}

If you don't see the answer to your question here, please [reach out to us](https://loadium.com/contact-us/) to let us know! We're always improving our documentation.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.loadium.com/jmeter-corner/handling-error-messages-of-jmeter-tests-in-loadium.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
