Fix exception when logging XML parse errors
This commit is contained in:
1 parent
d10fa2e073
commit
db3736e60b
1 file changed
+11
-16
+11
-16
@@ -189,14 +189,15 @@ async function writeResponse(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const httpResponse = sessionContext.httpResponse;
|
const httpResponse = sessionContext.httpResponse;
|
||||||
|
const connection = httpResponse.connection;
|
||||||
|
|
||||||
httpResponse.setHeader("Content-Length", Buffer.byteLength(data));
|
httpResponse.setHeader("Content-Length", Buffer.byteLength(data));
|
||||||
httpResponse.writeHead(res.code, res.headers);
|
httpResponse.writeHead(res.code, res.headers);
|
||||||
httpResponse.end(data);
|
|
||||||
|
|
||||||
if (sessionContext.debug)
|
if (sessionContext.debug)
|
||||||
debug.outgoingHttpResponse(httpResponse, sessionContext.deviceId, res.data);
|
debug.outgoingHttpResponse(httpResponse, sessionContext.deviceId, res.data);
|
||||||
|
httpResponse.end(data);
|
||||||
|
|
||||||
if (sessionContext.httpRequest.connection.destroyed) {
|
if (connection.destroyed) {
|
||||||
logger.accessError({
|
logger.accessError({
|
||||||
sessionContext: sessionContext,
|
sessionContext: sessionContext,
|
||||||
message: "Connection dropped"
|
message: "Connection dropped"
|
||||||
@@ -211,7 +212,7 @@ async function writeResponse(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sessionContext.lastActivity = Date.now();
|
sessionContext.lastActivity = Date.now();
|
||||||
currentSessions.set(sessionContext.httpRequest.connection, sessionContext);
|
currentSessions.set(connection, sessionContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -952,9 +953,9 @@ async function reportBadState(sessionContext: SessionContext): Promise<void> {
|
|||||||
const body = "Bad session state";
|
const body = "Bad session state";
|
||||||
httpResponse.setHeader("Content-Length", Buffer.byteLength(body));
|
httpResponse.setHeader("Content-Length", Buffer.byteLength(body));
|
||||||
httpResponse.writeHead(400, { Connection: "close" });
|
httpResponse.writeHead(400, { Connection: "close" });
|
||||||
httpResponse.end(body);
|
|
||||||
if (sessionContext.debug)
|
if (sessionContext.debug)
|
||||||
debug.outgoingHttpResponse(httpResponse, sessionContext.deviceId, body);
|
debug.outgoingHttpResponse(httpResponse, sessionContext.deviceId, body);
|
||||||
|
httpResponse.end(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function responseUnauthorized(
|
async function responseUnauthorized(
|
||||||
@@ -989,9 +990,9 @@ async function responseUnauthorized(
|
|||||||
const body = "Unauthorized";
|
const body = "Unauthorized";
|
||||||
httpResponse.setHeader("Content-Length", Buffer.byteLength(body));
|
httpResponse.setHeader("Content-Length", Buffer.byteLength(body));
|
||||||
httpResponse.writeHead(401, resHeaders);
|
httpResponse.writeHead(401, resHeaders);
|
||||||
httpResponse.end(body);
|
|
||||||
if (sessionContext.debug)
|
if (sessionContext.debug)
|
||||||
debug.outgoingHttpResponse(httpResponse, sessionContext.deviceId, body);
|
debug.outgoingHttpResponse(httpResponse, sessionContext.deviceId, body);
|
||||||
|
httpResponse.end(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processRequest(
|
async function processRequest(
|
||||||
@@ -1202,7 +1203,6 @@ async function listenerAsync(
|
|||||||
const _body = "Invalid session";
|
const _body = "Invalid session";
|
||||||
httpResponse.setHeader("Content-Length", Buffer.byteLength(_body));
|
httpResponse.setHeader("Content-Length", Buffer.byteLength(_body));
|
||||||
httpResponse.writeHead(400, { Connection: "close" });
|
httpResponse.writeHead(400, { Connection: "close" });
|
||||||
httpResponse.end(_body);
|
|
||||||
if (sessionContext.debug) {
|
if (sessionContext.debug) {
|
||||||
debug.outgoingHttpResponse(
|
debug.outgoingHttpResponse(
|
||||||
httpResponse,
|
httpResponse,
|
||||||
@@ -1210,7 +1210,7 @@ async function listenerAsync(
|
|||||||
_body
|
_body
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
httpResponse.end(_body);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (stats.concurrentRequests > MAX_CONCURRENT_REQUESTS) {
|
} else if (stats.concurrentRequests > MAX_CONCURRENT_REQUESTS) {
|
||||||
@@ -1270,7 +1270,6 @@ async function listenerAsync(
|
|||||||
});
|
});
|
||||||
httpResponse.setHeader("Content-Length", Buffer.byteLength(error.message));
|
httpResponse.setHeader("Content-Length", Buffer.byteLength(error.message));
|
||||||
httpResponse.writeHead(400, { Connection: "close" });
|
httpResponse.writeHead(400, { Connection: "close" });
|
||||||
httpResponse.end(error.message);
|
|
||||||
if (sessionContext) {
|
if (sessionContext) {
|
||||||
if (sessionContext.debug) {
|
if (sessionContext.debug) {
|
||||||
debug.outgoingHttpResponse(
|
debug.outgoingHttpResponse(
|
||||||
@@ -1285,13 +1284,10 @@ async function listenerAsync(
|
|||||||
remoteAddress: httpResponse.connection.remoteAddress
|
remoteAddress: httpResponse.connection.remoteAddress
|
||||||
});
|
});
|
||||||
if (d) {
|
if (d) {
|
||||||
debug.outgoingHttpResponse(
|
debug.outgoingHttpResponse(httpResponse, null, error.message);
|
||||||
httpResponse,
|
|
||||||
sessionContext.deviceId,
|
|
||||||
error.message
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
httpResponse.end(error.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1318,14 +1314,13 @@ async function listenerAsync(
|
|||||||
const _body = "Invalid session";
|
const _body = "Invalid session";
|
||||||
httpResponse.setHeader("Content-Length", Buffer.byteLength(_body));
|
httpResponse.setHeader("Content-Length", Buffer.byteLength(_body));
|
||||||
httpResponse.writeHead(400, { Connection: "close" });
|
httpResponse.writeHead(400, { Connection: "close" });
|
||||||
httpResponse.end(_body);
|
|
||||||
const cacheSnapshot = await localCache.getCurrentSnapshot();
|
const cacheSnapshot = await localCache.getCurrentSnapshot();
|
||||||
const d = !!localCache.getConfig(cacheSnapshot, "cwmp.debug", {
|
const d = !!localCache.getConfig(cacheSnapshot, "cwmp.debug", {
|
||||||
remoteAddress: httpResponse.connection.remoteAddress
|
remoteAddress: httpResponse.connection.remoteAddress
|
||||||
});
|
});
|
||||||
if (d)
|
if (d)
|
||||||
debug.outgoingHttpResponse(httpResponse, sessionContext.deviceId, _body);
|
debug.outgoingHttpResponse(httpResponse, sessionContext.deviceId, _body);
|
||||||
|
httpResponse.end(_body);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user