Keep status code on success

98 views
Skip to first unread message

Romain Grosjean

unread,
Jun 15, 2023, 9:12:02 AM6/15/23
to KrakenD Community
Hi all,

I don't know what I'm doing wrong of if I don't understand the doc but, I'm using krakend to call an endpoint of my backend, which returns 201 after creating a new resource on POST.

I found this https://www.krakend.io/docs/faq/ which leads me to https://www.krakend.io/docs/backends/detailed-errors/ and now my configuration looks like this:

{
"endpoint": "/persons",
"method": "POST",
"output_encoding": "json",
"backend": [
{
"url_pattern": "/rest/v1/persons",
"output_encoding": "json",
"method": "POST",
"extra_config": {
"backend/http": {
"return_error_code": true
}
}
]
}



It's working great for the errors but I'm still getting a 200 back krakend in case of success when the backend responds with 201.
I tried using a LUA script, but AFAIK, as long as I do not use encoding: "no-op", I can't change the status code programatically.

Is my configuration wrong? Is that a bug in KrakenD? Or is it just me not understanding the doc?

Thanks for your help


Romain Grosjean

unread,
Jun 15, 2023, 9:26:44 AM6/15/23
to KrakenD Community, Romain Grosjean
Oh, and I want to avoid using "no-op" because I may need to manipulate the answer in the future. :)

Albert Lombarte

unread,
Jun 15, 2023, 10:25:40 AM6/15/23
to KrakenD Community, romain.grosj...@gmail.com
Hi Romain,

KrakenD avoids backend coupling by not return their status codes, and choosing a 200 or 500 (generically speaking). The different strategies you can use to return error status codes apply to.... errors. Since 201 statuses are not considered errors, they don't follow this logic.

You need to use no-op in this case.

The status codes can be changed with Lua or response modifiers, but if you want to transfer them to the client, you must use no-op.

Responses can be still manipulated with Lua even when you have no-op.

Hope this helps

El dia dijous, 15 de juny de 2023 a les 15:26:44 UTC+2, romain.grosj...@gmail.com va escriure:

Romain Grosjean

unread,
Jun 15, 2023, 10:40:19 AM6/15/23
to KrakenD Community, Albert Lombarte, romain.grosj...@gmail.com
HI ALbert,

thanks for that quick answer :) I was referring to this part of the doc https://www.krakend.io/docs/faq/#explanation, where it sounds that it could even work for 201.
I'll have a look to no-op + Lua for the response, even if I have the feeling that I will not work. Another possibility would be to change the behaviour of our frontend. Nothing critical at the end.

Thanks again :)

Albert Lombarte

unread,
Jun 15, 2023, 11:25:55 AM6/15/23
to Romain Grosjean, KrakenD Community
Thanks Romain,

That is the most abandoned page in the documentation (my fault), it actually needs a little bit of caring, and that section is misleading.
Logo
Albert Lombarte
CEO

LinkedIn icon   Twitter icon  


Missatge de Romain Grosjean <romain.grosj...@gmail.com> del dia dj., 15 de juny 2023 a les 16:40:

Albert Lombarte

unread,
Jun 19, 2023, 10:18:54 AM6/19/23
to KrakenD Community, Albert Lombarte, KrakenD Community, romain.grosj...@gmail.com
The documentation has been changed.

El dia dijous, 15 de juny de 2023 a les 17:25:55 UTC+2, Albert Lombarte va escriure:
Thanks Romain,

That is the most abandoned page in the documentation (my fault), it actually needs a little bit of caring, and that section is misleading.
Logo
Albert Lombarte
CEO

LinkedIn icon   Twitter icon  


Missatge de Romain Grosjean <romain.grosjean.intension@gmail.com> del dia dj., 15 de juny 2023 a les 16:40:
Reply all
Reply to author
Forward
0 new messages