Skip to content

Commit

Permalink
Identify when a 577 error is thrown, send a new developer friendly me…
Browse files Browse the repository at this point in the history
…ssage (#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 <bronley@gmail.com>

* 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 <bronley@gmail.com>
  • Loading branch information
Christian-Holbrook and TwitchBronBron authored Nov 26, 2024
1 parent bfe0f5b commit eb544d7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/Errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
13 changes: 13 additions & 0 deletions src/RokuDeploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 10 additions & 2 deletions src/RokuDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}

Expand Down

0 comments on commit eb544d7

Please sign in to comment.