Skip to main content

NAuthHttpExceptionFilter

Package: @nauth-toolkit/nestjs Type: NestJS Exception Filter

Maps NAuthException to HTTP responses with appropriate status codes.

Import

import { NAuthHttpExceptionFilter } from '@nauth-toolkit/nestjs';

Usage

Global Registration

import { Module } from '@nestjs/common';
import { APP_FILTER } from '@nestjs/core';
import { NAuthHttpExceptionFilter } from '@nauth-toolkit/nestjs';

@Module({
providers: [
{
provide: APP_FILTER,
useClass: NAuthHttpExceptionFilter,
},
],
})
export class AppModule {}

Controller-Level

import { Controller, UseFilters } from '@nestjs/common';
import { NAuthHttpExceptionFilter } from '@nauth-toolkit/nestjs';

@Controller('auth')
@UseFilters(NAuthHttpExceptionFilter)
export class AuthController {}

Response Format

{
"statusCode": 429,
"code": "RATE_LIMIT_SMS",
"message": "Too many verification SMS sent",
"details": {
"retryAfter": 3600,
"currentCount": 4
},
"timestamp": "2025-10-31T12:00:00.000Z",
"path": "/auth/verify-phone"
}

Status Code Mapping

Status codes are determined by getHttpStatusForErrorCode():

Error Code PatternHTTP StatusExamples
RATE_LIMIT_*429RATE_LIMIT_SMS, RATE_LIMIT_LOGIN
AUTH_* (most)401INVALID_CREDENTIALS, TOKEN_INVALID, TOKEN_EXPIRED
AUTH_ACCOUNT_INACTIVE, AUTH_ACCOUNT_LOCKED403Account access blocked
SIGNUP_EMAIL_EXISTS, SIGNUP_USERNAME_EXISTS, SIGNUP_PHONE_EXISTS409Duplicate registration
SIGNUP_DISABLED403Signup not allowed
VALIDATION_*, INVALID_*400VALIDATION_FAILED, INVALID_PHONE
RESOURCE_NOT_FOUND404Resource not found
FORBIDDEN403Permission denied
INTERNAL_ERROR, SERVICE_UNAVAILABLE500Server errors
All others400Default
note

The table above uses the enum values (not the enum key names). For example, INVALID_CREDENTIALS is the enum key for the value AUTH_INVALID_CREDENTIALS, which matches the AUTH_* → 401 rule.