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

How do I create a request interceptor/middleware? #1492

Open
illunix opened this issue Nov 19, 2024 · 3 comments
Open

How do I create a request interceptor/middleware? #1492

illunix opened this issue Nov 19, 2024 · 3 comments
Labels
status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question

Comments

@illunix
Copy link
Contributor

illunix commented Nov 19, 2024

How do I create a request interceptor/middleware?

@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Nov 19, 2024
@baywet
Copy link
Member

baywet commented Nov 19, 2024

Here is an example of one, there are more in the parent directory.

export class RetryHandler implements Middleware {

Let us know if you have any additional comments or questions.

@baywet baywet added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question labels Nov 19, 2024
@baywet baywet moved this from Needs Triage 🔍 to Waits for author 🔁 in Kiota Nov 19, 2024
@illunix
Copy link
Contributor Author

illunix commented Nov 20, 2024

Any idea why it does not include this header in actual request but it shows in console? @baywet

  public async execute(
    url: string,
    reqInit: RequestInit,
    reqOptions?: Record<string, RequestOption>
  ): Promise<FetchResponse> {
    return this.executeInternal(url, reqInit as FetchRequestInit);
  }

  private async executeInternal(
    url: string,
    reqInit: FetchRequestInit
  ): Promise<Response> {
    setRequestHeader(reqInit as FetchRequestInit, 'Test', `Test`);

    console.log(reqInit as RequestInit);

    const res = await this.next?.execute(url, reqInit as RequestInit);
    if (!res) {
      throw new Error('Response is undefined');
    }

    return res;
  }

Image
Image

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Nov 20, 2024
@baywet
Copy link
Member

baywet commented Nov 20, 2024

Can you check what versions of the packages are actually installed and upgrade to the latest please? There used to be a a similar bug we fixed in #1358

@baywet baywet added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed Needs: Attention 👋 labels Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question
Projects
Status: Waits for author 🔁
Development

No branches or pull requests

2 participants