The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

App->halt() in Slim 3.x

Joscha Probst's Avatar

Joscha Probst

31 Dec, 2015 11:49 AM

Hi Guys,

in my v2 app i was using $app->halt(500, "error") in multiple places to stop the app if something went wrong. With a hook i was able then to log the message i was sending in $app->halt() and the status code was set correctly.
I am upgrading to v3 currently and the upgrade guide said that i should use $response->withStatus(500, "error") instead of $app->halt(500, "error").
The problem is, that $response->withStatus(500) is not stopping the app and if i am using it inside a class (not in the route directly) i only get an Internal Server Error instead of my custom message.

Someone got a tip for me how to replace $app->halt() properly in v3?

Thanks

Joscha

  1. 1 Posted by Rob Allen on 31 Dec, 2015 12:33 PM

    Rob Allen's Avatar

    Throw an exception and write your own errorHandler.

  2. 2 Posted by Sam on 09 Feb, 2016 05:38 PM

    Sam's Avatar

    Is there no simpler way than having to write my own errorHandler.

  3. 3 Posted by Jonathan on 12 Feb, 2016 03:48 AM

    Jonathan's Avatar

    You can just return a response with your desired status code and content.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac