# Set error message

**URL:** <https://community.postman.com/t/set-error-message/643>\
**Category:** Help Hub\
**Created:** [January 9, 2018, 3:29pm UTC](https://community.postman.com/t/set-error-message/643 "2018-01-09T15:29:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pieceofquality](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pieceofquality/32/236_2.png) [@pieceofquality](https://community.postman.com/u/pieceofquality)\
**Post date:** [January 9, 2018, 3:29pm UTC](https://community.postman.com/t/set-error-message/643/1 "2018-01-09T15:29:02Z")

</div>

How can I use custom message if test fails? For example, I have test:

> pm.test(“Status code is 200”, function () {  
> pm.response.to.have.status(200);  
> });

And I want see in results message about another status code in case of test failing (“Status code is 404”, “Status code is 500”, etc.)

---

<div class="post-metadata">

**Author:** ![dhoyt](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/dhoyt/32/238_2.png) [@dhoyt](https://community.postman.com/u/dhoyt)\
**Post date:** [January 9, 2018, 6:23pm UTC](https://community.postman.com/t/set-error-message/643/2 "2018-01-09T18:23:13Z")

</div>

Here is a very simple example …

```auto
if(responseCode.code != 200) { 
    tests["TEST FAILED - Expected responseCode is 200 ... responseCode received = " + responseCode.code] = responseCode.code === 200;
}
else {
    tests["TEST PASSED - responseCode is 200 ... responseCode received =" + responseCode.code] = responseCode.code === 200; 
}

```

---

<div class="post-metadata">

**Author:** ![aksbenz](https://avatars.discourse-cdn.com/v4/letter/a/b782af/32.png) [@aksbenz](https://community.postman.com/u/aksbenz)\
**Post date:** [January 9, 2018, 11:39pm UTC](https://community.postman.com/t/set-error-message/643/3 "2018-01-09T23:39:28Z")

</div>

You can also use the **pm.expect** along with **.equal** which accepts a second argument with custom message.

For example:

```javascript
pm.test('Status code', function() {
    pm.expect(pm.response.code).equal(200,'Status received is ' + pm.response.code);
});

```

---

<div class="post-metadata">

**Author:** ![dhoyt](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/dhoyt/32/238_2.png) [@dhoyt](https://community.postman.com/u/dhoyt)\
**Post date:** [January 10, 2018, 4:09pm UTC](https://community.postman.com/t/set-error-message/643/4 "2018-01-10T16:09:03Z")

</div>

This might be more inline with what he wants …

```auto
pm.test('Status received is ' + pm.response.code, function() {
    pm.expect(pm.response.code).equal(200);
});

```

This will always display the response code regardless if it is 200 or not. The “expect” works perfectly determining if its a PASS (green) or FAIL (red) in the output.
