custom message

"notifications": { "success": "Successful", "error": "Error (status code: {{statusCode}})", "undoable": "You have {{seconds}} seconds to undo", "createSuccess": "Successfully created {{resource}}", "createError": "There was an error creating {{resource}} (status code: {{statusCode}})", "deleteSuccess": "Successfully deleted {{resource}}", "deleteError": "Error when deleting {{resource}} (status code: {{statusCode}})", "editSuccess": "Successfully edited {{resource}}", "editError": "Error when editing {{resource}} (status code: {{statusCode}})", "importProgress": "Importing: {{processed}}/{{total}}" }, i want to showing response.errors instead of statusCode
K
kapa.ai189d ago
Hi @tuanna_. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In refine, you can customize the error notification message by using the errorNotification prop in various hooks such as useForm, useShow, useSelect, and useUpdateMany. This prop allows you to return a custom message, description, and type for the error notification. Here's an example of how you can show response.errors instead of statusCode:
useForm({
errorNotification: (data, values, resource) => {
return {
message: `Error: ${data.errors}`,
description: "Error",
type: "error",
};
},
});
useForm({
errorNotification: (data, values, resource) => {
return {
message: `Error: ${data.errors}`,
description: "Error",
type: "error",
};
},
});
In this example, data.errors will be displayed in the error notification message. Please replace useForm with the appropriate hook you are using. Remember, for this prop to work, NotificationProvider is required. Sources: - useForm (https://refine.dev/docs/api-reference/core/hooks/useForm/) - useShow (https://refine.dev/docs/api-reference/core/hooks/show/useShow/) - useSelect (https://refine.dev/docs/api-reference/core/hooks/useSelect/) - useUpdateMany (https://refine.dev/docs/api-reference/core/hooks/data/useUpdateMany/) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
K
kapa.ai189d ago
<@353701348463738885> kapa.ai is still learning and improving, please let us know how it did by reacting below
A
absent-sapphire189d ago
axiosInstance.interceptors.response.use( (response) => { return response; }, (error) => { const customError: HttpError = { ...error, message: error.response?.data?.message, statusCode: error.response?.data.status, }; return Promise.reject(customError); } ); @kapa.ai explain custom message
K
kapa.ai189d ago
Let me check the knowledge base for you. One moment! :books: ---------------------- In the provided code snippet, an Axios interceptor is being used to handle HTTP responses. Interceptors allow you to alter the request or response globally before they are handled by then or catch. Here's a breakdown of the code:
axiosInstance.interceptors.response.use(
(response) => {
return response;
},
(error) => {
const customError: HttpError = {
...error,
message: error.response?.data?.message,
statusCode: error.response?.data.status,
};

return Promise.reject(customError);
}
);
axiosInstance.interceptors.response.use(
(response) => {
return response;
},
(error) => {
const customError: HttpError = {
...error,
message: error.response?.data?.message,
statusCode: error.response?.data.status,
};

return Promise.reject(customError);
}
);
The axiosInstance.interceptors.response.use function takes two arguments: a function to handle a successful response and a function to handle an error response. In the case of a successful response, the response is simply returned as is. In the case of an error response, a custom error object is created and returned as a rejected Promise. This custom error object is of type HttpError and includes all properties of the original error (...error), but with the message and statusCode properties replaced by the corresponding properties from error.response.data. The message property is set to error.response?.data?.message, which means it will contain the error message returned by the server. The statusCode property is set to error.response?.data.status, which will contain the HTTP status code of the error response. This way, when an error occurs during an HTTP request, the error message and status code from the server response are included in the error object that is returned to the calling code. Source: Create a data provider from scratch - Error Handling (https://refine.dev/docs/tutorial/understanding-dataprovider/create-dataprovider/) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
K
kapa.ai189d ago
<@353701348463738885> kapa.ai is still learning and improving, please let us know how it did by reacting below
More Posts
Cancel queriesIs there an option to cancel all queries (not invalidate) and abort them? Something similar to: httpuseDataGrid not compatible with my apiconst { dataGridProps } = useDataGrid<IColor>({ pagination: { pageSize: 5, }, }); imChange id column name for useOne to anything other than "id"This seems like such an easy question to answer, but after hours of searching through the docs and aHow to fetch the data back present in the network preview after creating with hlp of useFormconst { saveButtonProps, onFinish, formLoading, formProps, queryResult } = useuseParams hook for get the passed query<Button style={{ backgroundColor: ConfigStyle.colors.primary, color: "whLaravel VueHello everyone, I am a full-stack developer who is fascinated by the sophisticated Refine frameworkuseGo<Button onClick={() => { go({ to: getToPath({ onClick show walk in record BOOKING IDonClick={() => show("walk_in", record?.BOOKING_ID)} onClick={() => { go({ I’m interested in the enterpriseI’m interested in the enterprise features but don’t have a non personal email for submitting the forrefetch data for table after mutation in create form componenthow do i force refetch data for table after mutation is completed in create form component both haveEdit page returning 404I'm encountering a 'Error 404' when clicking on an edit button for a row in a table. I've checked thIDataContextProvider MigrationI was using an IDataContextProvider with refine v3 to set some contextual data for subsequent CRUD vwhy is simple-rest automatically increasing _end query param to 25 instead of 10?Here is a screenshot of my mockAPI configuration and stub: wiremock endpoint: https://5z8l3.wiremocuseCan() Based off Page AccessHi! I'm currently using the following for action access on a table. ``` const { data: canAccess } how do i setup the refine project locally after cloning iti am having problem to set up locallyTwo Copies of UI?I am converting to using the ThemedLayoutV2 with Ant Design and now I have two copies of my UI. The