# Custom rpc response status in lua

**URL:** <https://forum.heroiclabs.com/t/custom-rpc-response-status-in-lua/619>\
**Category:** Local Setup\
**Created:** [April 9, 2020, 6:30pm UTC](https://forum.heroiclabs.com/t/custom-rpc-response-status-in-lua/619 "2020-04-09T18:30:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SinaZK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sinazk/32/134_2.png) [@SinaZK](https://forum.heroiclabs.com/u/SinaZK)\
**Post date:** [April 9, 2020, 6:30pm UTC](https://forum.heroiclabs.com/t/custom-rpc-response-status-in-lua/619/1 "2020-04-09T18:30:11Z")

</div>

I want to response different status codes for different payloads that comes to my custom rpc. Now if I return payload the status will be 200 and if I use error() the status will be 500. I want custom status codes (e.g. 400, 401…) And 500 is server internal error and it’s not clear as it should be for some conditions.

---

<div class="post-metadata">

**Author:** ![zyro](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/zyro/32/14_2.png) [@zyro](https://forum.heroiclabs.com/u/zyro)\
**Post date:** [April 10, 2020, 10:38am UTC](https://forum.heroiclabs.com/t/custom-rpc-response-status-in-lua/619/2 "2020-04-10T10:38:21Z")

</div>

The Lua runtime can inspect values you pass to the `error` function and determine if it can extract a message and response code. You can do this:

```auto
local message = "my error message"
local code = 13
error({message, code})

```

Where the code must be a GRPC response code numeric value from [this list](https://github.com/grpc/grpc/blob/master/doc/statuscodes.md) and will be mapped to a HTTP response code if necessary using [this translation](https://github.com/grpc-ecosystem/grpc-gateway/blob/master/runtime/errors.go#L17).
