0.13.1-4 release snapshot

This commit is contained in:
2026-04-13 11:52:07 +00:00
parent 6115090da1
commit ba3732af6b
176 changed files with 103457 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
module.exports = function asyncHandler(fn) {
return function wrapped(req, res, next) {
Promise.resolve(fn(req, res, next)).catch(next);
};
};
+23
View File
@@ -0,0 +1,23 @@
const logger = require('../services/logger').child('ERROR_HANDLER');
const { errorToMeta } = require('../utils/errorMeta');
module.exports = function errorHandler(error, req, res, next) {
const statusCode = error.statusCode || 500;
logger.error('request:error', {
reqId: req?.reqId,
method: req?.method,
url: req?.originalUrl,
statusCode,
error: errorToMeta(error)
});
res.status(statusCode).json({
error: {
message: error.message || 'Interner Fehler',
statusCode,
reqId: req?.reqId,
details: Array.isArray(error.details) ? error.details : undefined
}
});
};
+53
View File
@@ -0,0 +1,53 @@
const { randomUUID } = require('crypto');
const logger = require('../services/logger').child('HTTP');
function truncate(value, maxLen = 1500) {
if (value === undefined) {
return undefined;
}
let str;
if (typeof value === 'string') {
str = value;
} else {
try {
str = JSON.stringify(value);
} catch (error) {
str = '[unserializable-body]';
}
}
if (str.length <= maxLen) {
return str;
}
return `${str.slice(0, maxLen)}...[truncated ${str.length - maxLen} chars]`;
}
module.exports = function requestLogger(req, res, next) {
const reqId = randomUUID();
const startedAt = Date.now();
req.reqId = reqId;
logger.info('request:start', {
reqId,
method: req.method,
url: req.originalUrl,
ip: req.ip,
query: req.query,
body: truncate(req.body)
});
res.on('close', () => {
if (!res.writableEnded) {
logger.warn('request:aborted', {
reqId,
method: req.method,
url: req.originalUrl,
durationMs: Date.now() - startedAt
});
}
});
next();
};