Reputation: 395
I have developed simple posts endpoint and I do not know what to override and where to add status code. For example when some error happens I want to send 500
or when object created I want to send 201
instead of 200
.
How and where to set status code in response of strapi?
Upvotes: 2
Views: 6722
Reputation: 1758
Check out the strapi docs on responses, it uses a koa response object.
So you can do something like:
//controller
ctx.send({
message: 'The content was created!'
}, 201);
You can apply your own logic and response by using custom endpoints or modifying the existing ones. These are some closely related examples of how to do that - answer1 , answer2.
Comment if you need more info
Upvotes: 10