What to do best in case of error?

Hello,

In my app, I can have errors, for example if the user do not have enough credits to buy something.

In my previous website (pure php), I used to simply render the view with an error message.

But now, I’d like to send an http error code (404, 500…) and render a page with a message.

Therefore, should I just render a view and send a code ($response->withStatus(500)) or redirect to an error page ?

What is the best ?