Skip to content

Commit 6bef1f0

Browse files
committed
Improve auth error handling with UnauthorizedException
1 parent 86826bb commit 6bef1f0

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,5 @@ pids
5454

5555
# Diagnostic reports (https://nodejs.org/api/report.html)
5656
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
57+
yalc.*
58+
.yalc

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,8 @@
5656
"tsconfig-paths": "^4.2.0",
5757
"typescript": "^5.7.3",
5858
"typescript-eslint": "^8.20.0"
59+
},
60+
"dependencies": {
61+
"nestjs-offline-oauth2": "file:.yalc/nestjs-offline-oauth2"
5962
}
6063
}

src/auth.guard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ExecutionContext,
55
Injectable,
66
Logger,
7+
UnauthorizedException,
78
} from '@nestjs/common';
89
import { Reflector } from '@nestjs/core';
910
import { Roles } from './auth.decorators';
@@ -46,8 +47,7 @@ export class AuthGuard implements CanActivate {
4647
);
4748
return !!anyRoleMatch;
4849
} catch (error: unknown) {
49-
this.logger.warn((error as Error).message);
50-
return false;
50+
throw new UnauthorizedException(error);
5151
}
5252
}
5353
public getUserGroups(request: Request): string[] {

0 commit comments

Comments
 (0)