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

[Feature]: add failOnStatusCode to requestContext #34204

Open
fdm-mateco opened this issue Jan 3, 2025 · 1 comment
Open

[Feature]: add failOnStatusCode to requestContext #34204

fdm-mateco opened this issue Jan 3, 2025 · 1 comment
Labels
open-to-a-pull-request The feature request looks good, we are open to reviewing a PR

Comments

@fdm-mateco
Copy link

fdm-mateco commented Jan 3, 2025

🚀 Feature Request

When defining a (manual) API request context, one should be able to define failOnStatusCode. This should cause all requests done through this context to apply the flag (unless overridden).

const context = await request.newContext({
      baseURL: 'https://example/api/',
      extraHTTPHeaders: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${process.env.TOKEN}`,
      },
      failOnStatusCode: true
    });

Example

No response

Motivation

It will prevent repetitive code, as we'll no longer have to add the property on every API call as is now:

await this.context.get('contactpersons', { failOnStatusCode: true });
await this.context.get('addresses', { failOnStatusCode: true });
await this.context.get('customers', { failOnStatusCode: true });
@Skn0tt
Copy link
Member

Skn0tt commented Jan 9, 2025

Sounds good! I think it should be wrapped in apiRequest, like this:

const context = await request.newContext({
  baseURL: 'https://example/api/',
  extraHTTPHeaders: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${process.env.TOKEN}`,
  },
  apiRequest: {
    failOnStatusCode: true
  }
});

Would you be open to contribute a PR for this? The relevant code areas are:

Happy to contribute the patch myself if this isn't interesting to you.

@Skn0tt Skn0tt added the open-to-a-pull-request The feature request looks good, we are open to reviewing a PR label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-to-a-pull-request The feature request looks good, we are open to reviewing a PR
Projects
None yet
Development

No branches or pull requests

2 participants