# Response returning wrong status code

**URL:** <https://discourse.slimframework.com/t/response-returning-wrong-status-code/1229>\
**Category:** Questions\
**Created:** [March 4, 2017, 2:26am UTC](https://discourse.slimframework.com/t/response-returning-wrong-status-code/1229 "2017-03-04T02:26:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![qkzoo](https://avatars.discourse-cdn.com/v4/letter/q/839c29/32.png) [@qkzoo](https://discourse.slimframework.com/u/qkzoo)\
**Post date:** [March 4, 2017, 2:26am UTC](https://discourse.slimframework.com/t/response-returning-wrong-status-code/1229/1 "2017-03-04T02:26:23Z")

</div>

This always returns 200 [Ok] despite the fact I set -\>withStatus(400). Any advice on what I’ve screwed up here?

Thanks in advance!

```auto
// Get a single user by id
 11 $app->get('/user', function (Request $request, Response $response) {
 12 // Get the parameters
 13 $params = $request->getQueryParams();
 14 if (!isset($params['id']) || !is_numeric($params['id'])) {
 15 $newResponse = $response;
 16 $newResponse->withStatus(400)->write('Bad Request');
 17 return $newResponse;
 18 } ...
```

---

<div class="post-metadata">

**Author:** ![llvdl](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/llvdl/32/78_2.png) [@llvdl](https://discourse.slimframework.com/u/llvdl)\
**Post date:** [March 4, 2017, 9:44am UTC](https://discourse.slimframework.com/t/response-returning-wrong-status-code/1229/2 "2017-03-04T09:44:24Z")

</div>

`withStatus` returns a new instance of the response. Try:

```php
$newResponse = $response->withStatus(400)->write('Bad Request');
return $newResponse;

```

---

<div class="post-metadata">

**Author:** ![qkzoo](https://avatars.discourse-cdn.com/v4/letter/q/839c29/32.png) [@qkzoo](https://discourse.slimframework.com/u/qkzoo)\
**Post date:** [March 4, 2017, 2:41pm UTC](https://discourse.slimframework.com/t/response-returning-wrong-status-code/1229/3 "2017-03-04T14:41:01Z")

</div>

That fixed my issue, thank you so much!
