hey-api / openapi-ts

✨ Turn your OpenAPI specification into a beautiful TypeScript client
https://heyapi.vercel.app
MIT License
635 stars 44 forks source link

Fetch Response Interceptor Does Not Intercept 500s #710

Closed etash47 closed 5 days ago

etash47 commented 5 days ago

Description

I've tried using both the legacy fetch client and client-fetch, and I'm finding that the following code does not execute when when the response code is a 500.

const responseInterceptor = async (response: Response) => {
  if (response.status !== 500) {
    console.log('Non-500')
  } else {
      console.log('500');
  }
  return response;
};

OpenAPI.interceptors.response.use(responseInterceptor);

OpenAPI specification (optional)

0.47.2

Configuration

export default defineConfig({
  input: 'http://127.0.0.1:8000/openapi.json',
  output: './src/types/openapi',
  base: 'http://localhost:8000',
  services: { asClass: true },
});

System information (optional)

Chrome / Arc MacOS

mrlubos commented 5 days ago

@etash47 I believe you'll want to use the new Fetch API client for this

etash47 commented 5 days ago

@mrlubos I upgraded to @hey-api/client-fetch but now all my services are incorrectly typed :( When calling the service method, the response type is any instead of the specified ResponseType

Screenshot 2024-06-23 at 9 49 29 AM
export default defineConfig({
  client: '@hey-api/client-fetch',
  input: 'http://127.0.0.1:8000/openapi.json',
  output: './src/openapi',
  base: 'http://localhost:8000',
  types: {
    enums: 'typescript',
    dates: 'types+transform',
  },
  services: { asClass: true },
});
mrlubos commented 5 days ago

Can you create a StackBlitz example please?

etash47 commented 5 days ago

@mrlubos Apologies. I upgraded to Fetch API Client on a branch where I didn't have @hey-api/client-fetch installed. Working now!

(ps. this library has been an absolute gamechanger for us. Seriously appreciate the work you've put into this!!)

mrlubos commented 5 days ago

No worries @etash47, looks like you're working on some spacecraft/drone stuff? Sounds cool 🚀