Skip to content

Commit

Permalink
Merge pull request #8 from Mikescops/bugfix/prevent-crash-unknown-errors
Browse files Browse the repository at this point in the history
Prevent crash on unknown errors
  • Loading branch information
Mikescops authored Dec 28, 2023
2 parents 1aed6ab + 0625843 commit bfccbed
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/deviceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit bfccbed

Please sign in to comment.