add logError: boolean param to fetcher
Case for it is getUser api method. When user is not authenticated, api returns 403 error which pops up in console and have no meaning
This commit is contained in:
@@ -133,6 +133,7 @@ export const getUser = (): Promise<User | null> =>
|
||||
.get<User | null>({
|
||||
url: '/user',
|
||||
withCredentials: true,
|
||||
logError: false,
|
||||
})
|
||||
.catch(() => null);
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ interface FetcherInitBase {
|
||||
url: string;
|
||||
overriddenApiBase?: string;
|
||||
withCredentials?: boolean;
|
||||
/** whether log error message to console */
|
||||
logError?: boolean;
|
||||
}
|
||||
|
||||
interface FetcherInitJSON extends FetcherInitBase {
|
||||
@@ -34,6 +36,7 @@ const fetcher = methods.reduce<Partial<FetcherObject>>((acc, method) => {
|
||||
withCredentials = false,
|
||||
overriddenApiBase = API_BASE,
|
||||
contentType = 'application/json',
|
||||
logError = true,
|
||||
} = typeof data === 'string' ? { url: data } : data;
|
||||
const basename = `${BASE_URL}${overriddenApiBase}`;
|
||||
|
||||
@@ -81,8 +84,10 @@ const fetcher = methods.reduce<Partial<FetcherObject>>((acc, method) => {
|
||||
try {
|
||||
err = JSON.parse(text);
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(err);
|
||||
if (logError) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(err);
|
||||
}
|
||||
throw 'Something went wrong.';
|
||||
}
|
||||
throw err;
|
||||
|
||||
Reference in New Issue
Block a user