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
Hey @metammodern! I'm the kapa.ai support bot. I've searched through the docs to try to answer your question. :wave:
----------------------
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?
<@689885255921827855> kapa.ai is still learning and improving, please let us how it did by reacting below
harsh-harlequin•2y 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](https://cdn.answeroverflow.com/1088088104344244254/image.png)
optimistic-gold•2y 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:
harsh-harlequin•2y 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•2y 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•2y ago
Huh, that's odd
Okay, I'll provide screenshots tomorrow of what I see in vscode
harsh-harlequin•2y ago
@salihozdemir here's what I get
![No description](https://cdn.answeroverflow.com/1088406437966913576/image.png)
harsh-harlequin•2y ago
But I see that in d.ts in refine it's generic. So maybe I just wrote something incorrectly.
optimistic-gold•2y 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:
harsh-harlequin•2y ago
Okay, will do
Will the update go to v3 or v4?
optimistic-gold•2y ago
harsh-harlequin•2y ago
@salihozdemir https://github.com/refinedev/refine/pull/3965
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•2y ago
Thanks, we'll review your request and contact you shortly 🚀