From eb544d7156c71e2630723bd6e3f8925258eaf1b7 Mon Sep 17 00:00:00 2001 From: Christian-Holbrook <118202694+Christian-Holbrook@users.noreply.github.com> Date: Tue, 26 Nov 2024 10:39:30 -0700 Subject: [PATCH] Identify when a 577 error is thrown, send a new developer friendly message (#180) * Identify when a 577 error is thrown, send a new developer friendly message * Add unit test to get 100% coverage. Testing the publish 577 response code * Update src/Errors.ts Co-authored-by: Bronley Plumb * Rename the 577 error to updateCheckRequiredError. Pass the underlying error as the cause so developers can trace back to the root cause of the error --------- Co-authored-by: Bronley Plumb --- src/Errors.ts | 14 ++++++++++++++ src/RokuDeploy.spec.ts | 13 +++++++++++++ src/RokuDeploy.ts | 12 ++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/Errors.ts b/src/Errors.ts index e87ba2b..7f480aa 100644 --- a/src/Errors.ts +++ b/src/Errors.ts @@ -55,3 +55,17 @@ export class MissingRequiredOptionError extends Error { Object.setPrototypeOf(this, MissingRequiredOptionError.prototype); } } + +export class UpdateCheckRequiredError extends Error { + results: any; + + cause: Error; + + constructor(originalError: Error) { + super(); + this.message = `Your device needs to check for updates before accepting connections. Please navigate to System Settings and check for updates and then try again.\n\nhttps://support.roku.com/article/208755668.`; + this.results = { response: { statusCode: 577 } }; + this.cause = originalError; + Object.setPrototypeOf(this, UpdateCheckRequiredError.prototype); + } +} diff --git a/src/RokuDeploy.spec.ts b/src/RokuDeploy.spec.ts index 5dd4593..dfe03fc 100644 --- a/src/RokuDeploy.spec.ts +++ b/src/RokuDeploy.spec.ts @@ -1103,6 +1103,19 @@ describe('index', () => { }); }); + it('rejects when response contains invalid password status code', () => { + options.failOnCompileError = true; + mockDoPostRequest('', 577); + + return rokuDeploy.publish(options).then(() => { + assert.fail('Should not have succeeded due to roku server compilation failure'); + }, (err) => { + expect(err.message).to.be.a('string').and.satisfy(msg => msg.startsWith(`Your device needs to check for updates before accepting connections. Please navigate to System Settings and check for updates and then try again. + +https://support.roku.com/article/208755668.`)); + }); + }); + it('handles successful deploy', () => { options.failOnCompileError = true; mockDoPostRequest(); diff --git a/src/RokuDeploy.ts b/src/RokuDeploy.ts index 73392a9..7c3ccdd 100644 --- a/src/RokuDeploy.ts +++ b/src/RokuDeploy.ts @@ -468,8 +468,16 @@ export class RokuDeploy { if (this.isCompileError(replaceError.message) && options.failOnCompileError) { throw new errors.CompileError('Compile error', replaceError, replaceError.results); } else { - requestOptions.formData.mysubmit = 'Install'; - response = await this.doPostRequest(requestOptions); + try { + response = await this.doPostRequest(requestOptions); + } catch (installError: any) { + switch (installError.results.response.statusCode) { + case 577: + throw new errors.UpdateCheckRequiredError(installError); + default: + throw installError; + } + } } }