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

halt, $app->response()->status(500) not working

Musti's Avatar

Musti

05 Jul, 2012 06:49 PM

hi folks,

i have the problem that neither $app->halt(500) nor $app->resonse()->status(500) is working.
the response is always 200 (OK).
the code is something like this:

$app->delete('/delete/:id', 'delete'); function delete($id) {

$app = Slim::getInstance();
$db = new DB();
$result = $db->query("a query");
if(!$result) {
    echo json_encode(array('status' => "ERROR"));
    $app->halt(500);  //or $app->resonse()->status(500)
}

}

can anybody help me pls.

thx.

  1. Support Staff 1 Posted by Brian Nesbitt on 06 Jul, 2012 12:59 AM

    Brian Nesbitt's Avatar

    If I run the slightly modified version of your code it seems work work for me.

    http://127.0.0.1/delete/1 => Deleted userId : 1
    http://127.0.0.1/delete/2 => {"status":"ERROR"}
    http://127.0.0.1/delete/3 => Deleted userId : 3

    $app->get('/delete/:id', 'delete'); function delete($id) {
        $app = Slim::getInstance();
        if($id == 2) {
            $app->halt(500, json_encode(array('status' => "ERROR")));
        }
        echo "Deleted userId : " . $id;
    }
    

    Can you try this in a simple index.php file and let use know?

  2. 2 Posted by Musti on 06 Jul, 2012 03:30 PM

    Musti's Avatar

    hello brian,

    i just tried it out but in case of id==2
    i do not get anything. the server response is 200
    and body is empty.

    it works when i use the following

    echo json_encode(array('status' => "ERROR"));
    header('HTTP', true, 500);
    
  3. Support Staff 3 Posted by Brian Nesbitt on 06 Jul, 2012 04:04 PM

    Brian Nesbitt's Avatar

    What version of Slim are you using?

    Sent from my iPhone

  4. 4 Posted by Musti on 06 Jul, 2012 05:01 PM

    Musti's Avatar

    im using version 1.6.4

  5. Support Staff 5 Posted by Brian Nesbitt on 07 Jul, 2012 02:11 AM

    Brian Nesbitt's Avatar

    What version of PHP are you running?
    Can you paste your entire index.php for me?

  6. 6 Posted by famu1hundred on 14 Jun, 2014 01:11 AM

    famu1hundred's Avatar

    I have the exact same issue. HALT and STATUS always return 200 OK no matter what I set the parameter to. Any help on this would be appreciated

  7. 7 Posted by eluminous_sse18 on 24 Sep, 2014 10:35 AM

    eluminous_sse18's Avatar

    Hello , I have same issue, I am getting 200 as a responce with blank body,I will appreciate for any solution
    my index.php file is as below

  8. 8 Posted by Hardik Dave on 21 Aug, 2015 12:20 PM

    Hardik Dave's Avatar

    Facing the same issue. Did anyone find a solution?

  9. 9 Posted by Haddin on 26 Aug, 2015 03:13 AM

    Haddin's Avatar

    I have this issue too.

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