Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: update API code to use Axios instances#13029

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Parkreiner merged 7 commits intomainfrommes/axios-instances
Apr 24, 2024

Conversation

Parkreiner
Copy link
Member

@ParkreinerParkreiner commentedApr 22, 2024
edited
Loading

Addresses part of#13013

Changes made

  • Updated all references to the global Axios instance to a newaxiosInstance value
  • Updated the note about all the other codebases that we're importing the API file from

Notes

  • I still need to do some prodding to figure out the best way to improve test isolation for the Axios file. I'm 90% sure I'll have to refactor the file into a class, but there should be a way to abstract that detail away from anybody who isn't directly working with theapi.ts file
    • This would be in a separate PR, though

@ParkreinerParkreiner self-assigned thisApr 22, 2024
Copy link
MemberAuthor

@ParkreinerParkreinerApr 22, 2024
edited
Loading

Choose a reason for hiding this comment

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

Most of the file changes are here, but you can probably ignore everything past the first couple of lines. Main changes to the overall file:

  1. Updated the comment to list what exactly is importing the API file
  2. Updated all references for the globalaxios instance tocoderAxiosInstance
  3. ExportedcoderAxiosInstance
  4. Updated some of the calls toaxios.isAxiosError to justisAxiosError

kylecarbs reacted with thumbs up emoji
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel thatcoderAxiosInstance should never be exported or exposed. If we want to modify it, we should export custom functions for that.

Copy link
Member

Choose a reason for hiding this comment

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

@BrunoQuaresma it needs to be. The VS Code extension mutates it for request stuff.

BrunoQuaresma reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is interesting, I would not expect to see other packages/projects accessing theapi/api.ts directly.

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 that's ideal long-term. Replicate the codersdk in Go

code-asher reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

@code-asher Any preferences as for whether we have an optionalthrowOnError property that determines how the client resolves errors? I feel like it'd be good to default tofalse

Most of the time, I would like to do things the Go way, and expose the errors as values, but React Query is built on the assumption that if something fails, you just throw the error directly, and RQ will be the one to catch/sanitize it

Copy link
Member

Choose a reason for hiding this comment

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

Ohhh yeah good point, I forgot about how React Query does it. AthrowOnError property sounds like a good idea, but will that make the types difficult? Maybe we default to throwing for now, since that is the status quo anyway.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

So my thinking was that if you set up the client withthrowOnError = false, the usage looks like this:

const{ err, data}=awaitclient.getWorkspaces();

And if the client is set up to betrue, it looks like this:

// err no longer exists in the return typeconst{ data}=awaitclient.getWorkspaces();

We'd have to get a bit in the weeds of TypeScript's type system, and might have to do some type assertions for our own sanity, but I want to say it wouldn't be that bad

Copy link
Member

Choose a reason for hiding this comment

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

If the types seem chill then I am in support!

@ParkreinerParkreiner marked this pull request as ready for reviewApril 22, 2024 17:02
@Parkreiner
Copy link
MemberAuthor

Also want to ping you@code-asher so that you're aware of the changes for the VS Code plugin

code-asher reacted with thumbs up emojicode-asher reacted with heart emoji

@Parkreiner
Copy link
MemberAuthor

Anything I need to change to get this through? The Axios instance variable has already been renamed?

Copy link
Member

@code-ashercode-asher 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 to me!

@code-asher
Copy link
Member

Oh one comment, there is an example API call in frontend.md, idk if it really matters but we could update that to useaxiosInstance as well.

@Parkreiner
Copy link
MemberAuthor

Parkreiner commentedApr 23, 2024
edited
Loading

Oh one comment, there is an example API call in frontend.md, idk if it really matters but we could update that to useaxiosInstance as well.

Oh, good shout. Let me get that fixed

@ParkreinerParkreinerenabled auto-merge (squash)April 24, 2024 16:56
@ParkreinerParkreiner merged commit3f21cb8 intomainApr 24, 2024
@ParkreinerParkreiner deleted the mes/axios-instances branchApril 24, 2024 17:01
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsApr 24, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@kylecarbskylecarbskylecarbs left review comments

@code-ashercode-ashercode-asher approved these changes

@BrunoQuaresmaBrunoQuaresmaAwaiting requested review from BrunoQuaresma

Assignees

@ParkreinerParkreiner

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@Parkreiner@code-asher@BrunoQuaresma@kylecarbs

[8]ページ先頭

©2009-2025 Movatter.jp