Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry logic for ECP requests, on failure return our own error to make it more clear what failed #123

Merged
merged 1 commit into from
Dec 21, 2023

Conversation

triwav
Copy link
Owner

@triwav triwav commented Dec 20, 2023

This is been one of the issues I've struggled to track down for a while as it doesn't happen often and when it does the only message was socket hang up. I thought this was due to our socket logic between our code on the client and the component running on the device but this proved not to be true. We were not handling any errors when an ECP request fails and this was causing it ultimately bubble up the socket hang up error inside of Node. Now we will attempt to retry the request if retryCount is more than 0 and will throw a more useful error for the person running into the issue.

public async getActiveApp() {
const result = await this.device.sendEcpGet(`query/active-app`);
public async getActiveApp(options: HttpRequestOptions = {}) {
const result = await this.device.sendEcpGet(`query/active-app`, undefined, options);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish we didn't have to pass undefined for param3. :(

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could switch the second param to have something be something like

{
  params: params
  options: options
}

but that would be a breaking change for anyone using sendEcpGet

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I had discussed how to fix that in another comment, but you answered that as well. All good.

@@ -102,26 +107,40 @@ export class RokuDevice {
return updatedContents;
}

public sendEcpPost(path: string, params = {}, body: needle.BodyData = ''): Promise<needle.NeedleResponse> {
return this.sendEcp(path, params, body);
public sendEcpPost(path: string, params = {}, body: needle.BodyData = '', options: HttpRequestOptions = {}): Promise<needle.NeedleResponse> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we change the third parameter to be a single options object instead of needing to add a 4th param? I see you set needle.bodyData = ''. Will it always be a string? If so, we could maintain backwards compatibility by doing something like this:

public sendEcpPost(path: string, params = {}, options: SomethingHere) {
    let body: needle.BodyData;
    let actualOptions: HttpRequestOptions;
    if (typeof options === '') {
        body = options;
     } else {
         body = options?.body ?? '';
         actualOptions = options;
    }

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No body can be any of Buffer | KeyValue | NodeJS.ReadableStream | string | null; Often times it is passed as an object and it will automatically add the json header and encode it for you.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay. well then, I guess it's probably gotta stay the way you implemented it.

Copy link
Contributor

@TwitchBronBron TwitchBronBron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@triwav triwav merged commit 0f9a04a into master Dec 21, 2023
1 check passed
@triwav triwav deleted the add_retry_logic_for_ecp_requests branch December 21, 2023 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants