UNPKG

@next-nest-auth/nestauth

Version:

NestAuth is an authentication solution for NestJS applications, designed to handle user login, session management, and token-based authentication (JWT). It integrates seamlessly with Next.js and other frontends to provide a unified authentication system,

65 lines 2.78 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HttpExceptionFilter = void 0; const common_1 = require("@nestjs/common"); let HttpExceptionFilter = class HttpExceptionFilter { catch(exception, host) { const ctx = host.switchToHttp(); const response = ctx.getResponse(); const request = ctx.getRequest(); let status = 500; let message = "Internal Server Error"; if (exception instanceof common_1.HttpException || (exception?.status && exception?.response)) { status = exception.status ?? 500; const exceptionResponse = exception.response ?? exception.getResponse?.(); if (typeof exceptionResponse === "string") { message = exceptionResponse; } else if (typeof exceptionResponse === "object" && exceptionResponse.message) { message = exceptionResponse.message; } else if (typeof exceptionResponse === "object" && exceptionResponse.error) { message = exceptionResponse.error; } } else { console.error("Unexpected error:", exception); } const responseBody = { statusCode: status, message, path: request?.url, app: "nestauth", }; try { if (typeof response.status === "function" && typeof response.json === "function") { response.status(status).json(responseBody); } else if (typeof response.send === "function") { response.code?.(status); response.send(responseBody); } else { console.error("Unsupported response object:", response); } } catch (err) { console.error("Error while sending error response:", err); } } }; exports.HttpExceptionFilter = HttpExceptionFilter; exports.HttpExceptionFilter = HttpExceptionFilter = __decorate([ (0, common_1.Catch)() ], HttpExceptionFilter); //# sourceMappingURL=http-exception.filter.js.map