I am working with jwt authorization. I want to handle the wrong number of segment error.
public function token()
{
if ($this->request->is(‘post’)) {
$user = $this->Auth->identify();
$this->set([
‘success’ => true,
‘user’ => $user,
‘data’ => [
‘token’ => $token = \Firebase\JWT\JWT::encode([
‘id’ => $user[‘id’],
‘exp’ => time() + 604800,
],
Security::salt()),
],
‘_serialize’ => [‘success’, ‘data’ ,‘user’],
]);
}
else {
throw new UnauthorizedException(“Invalid email or password, try again”);
}
}
https://localhost/cakephp/forms.json
Method : POST
Content-Type:application/json
Authorization:Bearer df41564621212
{
“message”: “Wrong number of segments”,
“url”: “/forms.json”,
“code”: 500,
“file”: “E:\xampp\htdocs\cakephp\vidhya-venkatesan\vendor\firebase\php-jwt\src\JWT.php”,
“line”: 78
}
I want to handle the error when token is incorrect. Can someone help please.