anttiviljami / react-openapi-client

Consume OpenAPI-enabled APIs with React Hooks
MIT License
57 stars 10 forks source link

Retry When Init Fails #52

Open mwaeckerlin opened 2 years ago

mwaeckerlin commented 2 years ago

When the client instantiates the server offline, connection will never be established. Currently, in the code you catch the error, but do nothing with it. It would be nice, if that would update automatically when going online.

Therefore, I suggest to add a timer with a retry timer given in the properties (with some meaningful default, e.g. 5000ms). It could retry not only on initSyng (when reading the JSON definition), but also if a request fails.

e.g.

const App = () => (
  <OpenAPIProvider retry="5000" definition="http://petstore.swagger.io:8080/api/v3/openapi.json">
    <PetDetails id={1} />
  </OpenAPIProvider>
)