Copyright © https://mongoose-os.com

Mongoose OS Forum

frame
ATTENTION! This forum has moved to:

https://community.mongoose-os.com

Do not post any new messages.

mg_rpc_send_errorf() always results in code 500

Hi everyone,

When our users send HTTP POST with incomplete information, our rpc handler sends:

mg_rpc_send_errorf(ri, 400, "Bad Request");

Result:

But as you can see above, the message Bad Request shows up OK, but with the wrong error code. It is always 500.

We always get 500 no matter what code we put in as the second argument to mg_rpc_send_errorf(). Any help would be greatly appreciated!
Andrew

Comments

  • Here is the timeline for more information:

  • I think I see the culprit in mg_rpc_channel_http.c:

          if (error_code != 404) error_code = 500;
    

    Is there any way I can send a non-404 error without modifying the library (which I might accidentally overwrite the next time I clone/update it)?

  • SergeySergey Dublin, Ireland

    The RPC is transport-agnostic, meaning that RPC error code, which is passed in a error frame {"error": {"code": ..., ...}}, might not be HTTP.
    It'd be a mistake to pass RPC error directly as a HTTP response code.
    Can't you catch the frame and use the value from the frame ?

Sign In or Register to comment.