Using response data in errorNotification useForm

Hello, My REST API sends a JSON with explanation of what's wrong with the response when request fails(4xx response code) . How do I use that response data inside errorNotification property of useForm hook? In error argument I only have an Error object, not the response data.
26 Replies
kapa.ai
kapa.ai2y ago
Hey @metammodern! I'm the kapa.ai support bot. I've searched through the docs to try to answer your question. :wave:
kapa.ai
kapa.ai2y ago
---------------------- Hmm, I don't know enough to give you a confident answer yet. However, you can refer to the refine documentation (https://refine.dev/docs) for more information on how to handle specific scenarios with the hooks provided by refine. ----------------------
Overview | refine
What is refine?
kapa.ai
kapa.ai2y ago
<@689885255921827855> kapa.ai is still learning and improving, please let us how it did by reacting below
harsh-harlequin
harsh-harlequin2y ago
Okay, nevermind, I found out how to do it. There is a response object in that error. Is there a way to add correct typings for the errorNotification and successNotification functions in useForm?
No description
optimistic-gold
optimistic-gold2y ago
Hey @metammodern, You can checkout our useForm doc and see errorNotification and successNotification sections here: https://refine.dev/docs/api-reference/core/hooks/useForm/#errornotification Also, you can see useForm type params in here: https://refine.dev/docs/api-reference/core/hooks/useForm/#type-parameters You can give types like following:
useForm<TData, TError, TVariables>()
useForm<TData, TError, TVariables>()
harsh-harlequin
harsh-harlequin2y ago
Thank you. In v3.x.x.x do those type pass into functions correctly? Because for all parameters I have "unknown" type. Also, I saw the documentation, it lacks examples of using response data
optimistic-gold
optimistic-gold2y ago
All of them avaible in v3. Actually, all of generics has default types different from “unknown”. I think this must be what you're looking at: https://refine.dev/docs/api-reference/core/providers/data-provider/#error-format
Data Provider | refine
The data provider acts as a data layer for your app that makes the HTTP requests and encapsulates how the data is retrieved. refine consumes these methods via data hooks.
harsh-harlequin
harsh-harlequin2y ago
Huh, that's odd Okay, I'll provide screenshots tomorrow of what I see in vscode
harsh-harlequin
harsh-harlequin2y ago
@salihozdemir here's what I get
No description
harsh-harlequin
harsh-harlequin2y ago
But I see that in d.ts in refine it's generic. So maybe I just wrote something incorrectly.
optimistic-gold
optimistic-gold2y ago
Hey @metammodern, You're absolutely right, it's a bug. We missed to pass generic types to SuccessErrorNotification interface. You can see in here: https://github.com/refinedev/refine/blob/next/packages/core/src/hooks/form/useForm.ts#L140 Can you create an PR for this? All you have to do is change this line:
- SuccessErrorNotification
+ SuccessErrorNotification<TData, TError, TVariables>
- SuccessErrorNotification
+ SuccessErrorNotification<TData, TError, TVariables>
harsh-harlequin
harsh-harlequin2y ago
Okay, will do Will the update go to v3 or v4?
optimistic-gold
optimistic-gold2y ago
You can create a branch on next. For more details: https://refine.dev/docs/contributing/
harsh-harlequin
harsh-harlequin2y ago
GitHub
WIP: Update Generic Typings for useForm and useCustomMutation Notif...
IMPORTANT: Please do not create a Pull Request without creating an issue first. Any change needs to be discussed before proceeding. Failure to do so may result in the rejection of the pull request....
optimistic-gold
optimistic-gold2y ago
Thanks, we'll review your request and contact you shortly 🚀