6989a98d75
- Arkitektur: docs/auth/passwordless-architecture.md - Backend: iom/quixzoom-auth-service/ (FastAPI + Redis) - Webb: quixzoom-market-pages/se/login/ (QR-kod + polling) - App: iom/quixzoom-app/src/features/auth/ (push + deep links) Flöde: QR-kod → app-godkännande → webb-inloggad
29 lines
1.1 KiB
JavaScript
29 lines
1.1 KiB
JavaScript
import { getStatusCode } from '../../status-code.js';
|
|
import { sanitize } from '../../utils/sanitize.js';
|
|
import { definePlugin } from '../define-plugin.js';
|
|
function isResponseLike(obj) {
|
|
return obj && typeof obj.writeHead === 'function';
|
|
}
|
|
function isSocketLike(obj) {
|
|
return obj && typeof obj.write === 'function' && !('writeHead' in obj);
|
|
}
|
|
export const errorResponsePlugin = definePlugin((proxyServer, options) => {
|
|
proxyServer.on('error', (err, req, res, target) => {
|
|
// Re-throw error. Not recoverable since req & res are empty.
|
|
if (!req || !res) {
|
|
throw err; // "Error: Must provide a proper URL as target"
|
|
}
|
|
if (isResponseLike(res)) {
|
|
if (!res.headersSent) {
|
|
const statusCode = getStatusCode(err.code);
|
|
res.writeHead(statusCode);
|
|
}
|
|
const host = req.headers && req.headers.host;
|
|
res.end(`Error occurred while trying to proxy: ${sanitize(host)}${sanitize(req.url)}`);
|
|
}
|
|
else if (isSocketLike(res)) {
|
|
res.destroy();
|
|
}
|
|
});
|
|
});
|