Skip to content

Commit a927796

Browse files
committed
add specific condition handler if user data can not be found
1 parent 1d4ff9c commit a927796

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎src/controllers/UsersController.php‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,19 @@ public function getAllUser() {
2525
public function getUserById($id) {
2626
$result = $this->user->getUserById($id);
2727

28-
http_response_code(200);
2928
header('Content-Type: application/json');
29+
30+
if (empty($result)) {
31+
http_response_code(404);
32+
$message = "user not found";
33+
} else {
34+
http_response_code(200);
35+
$message = "successfully get user data from database";
36+
}
37+
3038
$response = [
3139
"status"=>"success",
32-
"message"=> "successfully get user data from database",
40+
"message"=> $message,
3341
"data"=> $result
3442
];
3543
echo json_encode($response);

0 commit comments

Comments
 (0)