Skip to content

Commit

Permalink
Add custom exception
Browse files Browse the repository at this point in the history
  • Loading branch information
quangdung93 committed Sep 8, 2021
1 parent e5488b2 commit 7b9d9cb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
11 changes: 11 additions & 0 deletions src/Exceptions/JwtRedisException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Ajax\JwtRedis\Exceptions;

use Exception;

class JwtRedisException extends Exception
{
protected $message = 'API request Invalid';
protected $code = 401;
}
2 changes: 1 addition & 1 deletion src/JwtRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getTokenBySessionIdFromRedis($session_id):array

public function hashKey(array $params):string
{
return md5(implode('.', $params));
return sha1(implode('.', $params));
}

}
12 changes: 4 additions & 8 deletions src/Middleware/JwtRedisMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Ajax\JwtRedis\Middleware;

use Closure;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
use Ajax\JwtRedis\Facades\JwtRedis;
use Illuminate\Support\Facades\Auth;
use Ajax\JwtRedis\Exceptions\JwtRedisException;

class JwtRedisMiddleware
{
Expand Down Expand Up @@ -39,14 +39,10 @@ public function handle($request, Closure $next)
}
}

return response()->json([
'error' => 'API request Invalid.',
], Response::HTTP_UNAUTHORIZED);
throw new JwtRedisException();

}catch (\Exception $e) {
return response()->json([
'error' => $e->getMessage(),
], Response::HTTP_UNAUTHORIZED);
throw new JwtRedisException();
}

}
Expand Down

0 comments on commit 7b9d9cb

Please sign in to comment.