baseResult can return an error if an error occured and we can use that to track which endpoint had an error. api parameter has an endpoint value that has the name of the endpoint (eg getUserById from the above example).
const baseResult = await fetchBaseQuery({ baseUrl: "/api" })(
args,
api,
extraOptions
);
if (baseResult.error) {
const error = baseResult.error;
if ("status" in error) {
const errMsg = "error" in error ? error.error : JSON.stringify(error.data);
console.error(`Error with ${api.endpoint}: ${error}`);
}
}
Implementing a custom RTK Query baseQuery
In RTK Query, services are created like this example:
The
baseQuerycan be a custom utility that can wrap the defaultfetchBaseQuery.Below is use-case that provides meta along with each request:
baseResultcan return anerrorif an error occured and we can use that to track which endpoint had an error.apiparameter has anendpointvalue that has the name of the endpoint (eggetUserByIdfrom the above example).