template-fastapi-react icon indicating copy to clipboard operation
template-fastapi-react copied to clipboard

refactor: generic fetch function in useTodoAPI

Open olavis opened this issue 2 years ago • 2 comments

        .catch((error: AxiosError<ErrorResponse>) => {
          throw new Error(error.message)
        })
          This one is repeated 4 times. Perhaps refactor?

Originally posted by @ingeridhellen in https://github.com/equinor/template-fastapi-react/pull/195#discussion_r1132372291

olavis avatar Mar 13 '23 10:03 olavis

Looked into this, but I found it hard to find an elegant way to solve it in other ways than just writing a common catch function. In my opinion, the requests differ too much to make it worth it. The API lacks consistent response types and has built-in functions for create, getAll etc, instead of relying upon standard OpenAPI paths. It makes it hard to bring out the essence of the functions without adding extra checks. IMO, a common catch function would be a hasty abstraction (see AHA-programming), but I'll let the issue stay up for grabs if anyone wants to fix it from the backend. ✌️

olavis avatar Mar 13 '23 14:03 olavis

#155 should be resolved first

olavis avatar Mar 15 '23 07:03 olavis