refinedev / refine

A React Framework for building internal tools, admin panels, dashboards & B2B apps with unmatched flexibility.
https://refine.dev
MIT License
25.92k stars 1.96k forks source link

[BUG] errorNotification has invalid argument type #6056

Closed CRC32EX closed 1 week ago

CRC32EX commented 1 week ago

Describe the bug

errorNotification 's 1st argument is error. But, The real type is Response, Please fix it.

image

And, please support async / await. I want write code, like this.

Steps To Reproduce

 refineCoreProps: {
      errorNotification: (error) => {
        console.log("on error notification")

        // const response = error as unknown as Response
        console.log(error)

        const obj = await response.json() as MyErrorType
        return {
          type: "error",
          message: obj.message,
          description: obj.description,
        } as OpenNotificationParams
      },
    },

Expected behavior

Packages

Next.js

Additional Context

No response

HussainAther commented 1 week ago

Change the Argument Type: Update the argument type of the errorNotification function to match the actual type (Response). Support Async/Await: Modify the function to support async/await syntax. For example, if the function is defined in a TypeScript file, it might look like this:

import { OpenNotificationParams } from 'path/to/type/definition';

async function errorNotification(response: Response): Promise { console.log("on error notification"); console.log(response);

const obj = await response.json() as MyErrorType;
return {
    type: "error",
    message: obj.message,
    description: obj.description,
};

}

HussainAther commented 1 week ago

Excuse me, I just wanted to make suggestions. I'll be more thorough if I can get to this later, thanks.

BatuhanW commented 1 week ago

Could you be more clear with what do you mean? This might return response or anything else, it depends on the situtation. But what Refine needs is this error structure. These fields will be used to render error notification. It may have more fields than that, but they are redundant.