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

fix: add echo requester and fix timeouts #14

Merged
merged 4 commits into from
Nov 25, 2021
Merged

Conversation

millotp
Copy link
Collaborator

@millotp millotp commented Nov 24, 2021

Add possibility to change requester, and include a basic echo requester that sends the request back, used for the CTS.

Also fixes the read/write timeouts, the read/write hosts, and make the flow a little bit clearer.

@millotp millotp self-assigned this Nov 24, 2021
@millotp millotp requested review from shortcuts and damcou November 24, 2021 14:19
import { Response } from './types';

export function isNetworkError({ isTimedOut, status }: Omit<Response, 'content'>): boolean {
return !isTimedOut && ~~status === 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I get the ~~status === 0 part of this check? Do we get a status of 0 back when there's a network error?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's when there's no response at all

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I copied it from the existing client, I don't know why there is the ~~ but yes, here it indicates an error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, thanks for clarifying! The ~~ ensures we're always working with an integer (even if status is a string etc), without impacting performance too much.

StackOverflow

shortcuts
shortcuts previously approved these changes Nov 24, 2021
Copy link
Member

@shortcuts shortcuts left a comment

Choose a reason for hiding this comment

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

Changes looks good on my side!

Only thing is that we should start documenting:

  • the changes done between the current client implementation and the new clients
  • what should be manually added in a client to make it work like the JS one

It will help us implement future clients and also simplify the work if we need external contributors

import { Response } from './types';

export function isNetworkError({ isTimedOut, status }: Omit<Response, 'content'>): boolean {
return !isTimedOut && ~~status === 0;
Copy link
Member

Choose a reason for hiding this comment

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

I think it's when there's no response at all

@shortcuts
Copy link
Member

(PR title is fi btw 🤔 )

@millotp millotp changed the title fi: add echo requester and fix timeouts fix: add echo requester and fix timeouts Nov 24, 2021
@@ -32,7 +32,7 @@ export class SearchApi {

protected interceptors: Interceptor[] = [];

constructor(appId: string, apiKey: string) {
constructor(appId: string, apiKey: string, requester?: Requester) {
this.setApiKey(SearchApiApiKeys.appId, appId);
this.setApiKey(SearchApiApiKeys.apiKey, apiKey);
this.transporter = new Transporter({
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not in the scope of this PR, but just wanted to make sure everyone's aware of this; I would recommend making the hosts (or the whole transporter) something you can pass to the constructor as well. Once Metis is released, the client would need to work with different hosts than the one we set by default.

Copy link
Member

Choose a reason for hiding this comment

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

Do you think we should prepare this codebase for Metis even if we don't have an ETA?

Copy link
Member

Choose a reason for hiding this comment

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

(Does not cost anything, but just wondering)

Copy link
Contributor

Choose a reason for hiding this comment

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

It's good to keep in mind for sure, otherwise we might have to rework a lot later on 🙂 Besides the hosts part, not a lot should change, though (perhaps the retry strategy but that is a problem for later 😄 )

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point I'll include the host too

Copy link
Member

@shortcuts shortcuts left a comment

Choose a reason for hiding this comment

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

(reviewed in sync with @damcou and @millotp)

@millotp millotp merged commit d3af41e into main Nov 25, 2021
@millotp millotp deleted the fix/echo-requester branch November 25, 2021 16:38
@shortcuts
Copy link
Member

🔨 The codegen job will run at the end of the CI.

_Make sure your last commit does not contains generated code, it will be automatically pushed by our CI.

@shortcuts
Copy link
Member

oops

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.

4 participants