From 06258432dc9e0293472e3ab04ce571af89460181 Mon Sep 17 00:00:00 2001 From: Corentin Mors Date: Thu, 28 Dec 2023 17:12:46 +0100 Subject: [PATCH] Prevent crash on unknown errors --- src/deviceClient.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/deviceClient.ts b/src/deviceClient.ts index faea0b7..b695f91 100644 --- a/src/deviceClient.ts +++ b/src/deviceClient.ts @@ -162,10 +162,13 @@ export class UpnpDeviceClient extends EventEmitter { const responseDoc = et.parse(response.body.toString()); if (response.statusCode !== 200) { - const errorCode = parseInt(responseDoc.findtext('.//errorCode').toString()); - const errorDescription = responseDoc.findtext('.//errorDescription').toString().trim(); + const errorCode = responseDoc.findtext('.//errorCode').toString() ?? '0'; + const errorDescription = responseDoc.findtext('.//errorDescription').toString().trim() ?? 'Unknown error'; - throw new UpnpError('EUPNP', errorDescription, { errorCode, httpCode: response.statusCode }); + throw new UpnpError('EUPNP', errorDescription, { + errorCode: parseInt(errorCode), + httpCode: response.statusCode + }); } // Extract response outputs @@ -177,7 +180,7 @@ export class UpnpDeviceClient extends EventEmitter { const result = {}; outputs.forEach((name) => { - result[name] = responseDoc.findtext('.//' + name).toString(); + result[name] = responseDoc.findtext('.//' + name).toString() ?? ''; }); return result;