UNPKG

powr-sdk-api

Version:

Shared API core library for PowrStack projects. Zero dependencies - works with Express, Next.js API routes, and other frameworks. All features are optional and install only what you need.

29 lines (26 loc) 806 B
"use strict"; const logger = require("../logger"); // Handler for 404 Not Found errors const notFoundHandler = (req, res) => { // Log the 404 error logger.warn(`Route not found: ${req.method} ${req.path}`, { requestId: req.requestId, ip: req.ip, userAgent: req.headers['user-agent'] }); // Check if res.error is available (from requestHandler) if (res.error) { return res.error('The requested resource was not found', 404, `${req.method} ${req.path}`); } // Fallback 404 handling if res.error is not available const response = { success: false, message: 'The requested resource was not found', requestId: req.requestId || 'unknown', path: `${req.method} ${req.path}` }; return res.status(404).json(response); }; module.exports = { notFoundHandler };