fix(auth): migrate raw Error throws to DomainException (GOO-52)
Replace 9 raw `throw new Error(...)` instances in the auth module with typed DomainException subclasses so the GlobalExceptionFilter produces structured error responses with proper HTTP status codes and error codes. - zalo-oauth.strategy.ts (4): AUTH_OAUTH_PROVIDER_ERROR / 502 - jwt.strategy.ts (1): AUTH_CONFIG_MISSING / 500 - auth.module.ts (1): AUTH_CONFIG_MISSING / 500 - oauth.service.ts (3): AUTH_ACCOUNT_DISABLED / 403 - Add AUTH_OAUTH_PROVIDER_ERROR, AUTH_CONFIG_MISSING, AUTH_ACCOUNT_DISABLED to ErrorCode enum - Update jwt.strategy.spec.ts mock to export DomainException + ErrorCode Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -3,7 +3,7 @@ import { PassportStrategy } from '@nestjs/passport';
|
||||
import { type Request } from 'express';
|
||||
import { ExtractJwt, Strategy } from 'passport-jwt';
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-imports -- NestJS DI requires value imports for emitDecoratorMetadata
|
||||
import { PrismaService, RedisService } from '@modules/shared';
|
||||
import { PrismaService, RedisService, DomainException, ErrorCode } from '@modules/shared';
|
||||
import { type JwtPayload } from '../services/token.service';
|
||||
|
||||
function extractJwtFromCookieOrHeader(req: Request): string | null {
|
||||
@@ -34,7 +34,7 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
|
||||
) {
|
||||
const jwtSecret = process.env['JWT_SECRET'];
|
||||
if (!jwtSecret) {
|
||||
throw new Error('JWT_SECRET environment variable is required');
|
||||
throw new DomainException(ErrorCode.AUTH_CONFIG_MISSING, 'JWT_SECRET environment variable is required');
|
||||
}
|
||||
|
||||
super({
|
||||
|
||||
Reference in New Issue
Block a user