making custom errorNotification in mutate function under useDelete hook
I'm getting this error on trying to delete an entry.
Foreign key violation. update or delete on table "departments" violates foreign key constraint "sub_departments_department_id_fkey" on table "sub_departments": {"response":{"errors":[{"extensions":{"code":"constraint-violation","path":"$"},"message":"Foreign key violation.
I need to change this error into my own custom error message.
I'm using,
const { mutate } = useDelete();
under the mutate function,
onClick={
() =>
mutate({
id: record.id,
resource: "departments",
})
}
Here I've to pass errorNotification property and modify the above default notification message into my custom message.
@Omer
4 Replies
Hey @coops8 š ,
Thank you for contacting us! You can use
errorNotification
property of useDelete
hook šÆ
https://refine.dev/docs/api-reference/core/hooks/data/useDelete/#properties
initial-roseā¢2y ago
Thanks @Omer ...
useDelete was expecting 0 arguments
Sorry my mistake. You can pass it to the "mutate" function
initial-roseā¢2y ago
so according to me instead of writing in the useDelete hook as an argument... we can pass it as an in the mutate ... like this
š
mutate({
id: record.id,
resource: "departments",
errorNotification: (error, values, resource) => ({
message: error
? "Department cannot be removed"
: "Department removed",
type: "error",
description: "Prohibited!!",
}),
})
exactly š