mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-01 13:06:45 +00:00
API error handling (#8739)
* API error handling - Add error handlers to various API calls * Fix return type
This commit is contained in:
parent
933330fa51
commit
f31ba657cc
@ -15,6 +15,7 @@ import {
|
|||||||
} from '@tabler/icons-react';
|
} from '@tabler/icons-react';
|
||||||
|
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
|
import { showNotification } from '@mantine/notifications';
|
||||||
import { api } from '../../App';
|
import { api } from '../../App';
|
||||||
import { ApiEndpoints } from '../../enums/ApiEndpoints';
|
import { ApiEndpoints } from '../../enums/ApiEndpoints';
|
||||||
import { apiUrl } from '../../states/ApiState';
|
import { apiUrl } from '../../states/ApiState';
|
||||||
@ -46,6 +47,13 @@ export function SsoButton({ provider }: Readonly<{ provider: Provider }>) {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
// redirect to login
|
// redirect to login
|
||||||
window.location.href = provider.login;
|
window.location.href = provider.login;
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
showNotification({
|
||||||
|
title: t`Error`,
|
||||||
|
message: t`Sign in redirect failed.`,
|
||||||
|
color: 'red'
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,8 @@ export default function NewsWidget() {
|
|||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
newsItems.refetch();
|
newsItems.refetch();
|
||||||
});
|
})
|
||||||
|
.catch(() => {});
|
||||||
},
|
},
|
||||||
[newsItems]
|
[newsItems]
|
||||||
);
|
);
|
||||||
|
@ -48,7 +48,8 @@ function QueryCountWidget({
|
|||||||
limit: 1
|
limit: 1
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then((res) => res.data);
|
.then((res) => res.data)
|
||||||
|
.catch(() => {});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ import { useDisclosure } from '@mantine/hooks';
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useLocation, useNavigate } from 'react-router-dom';
|
import { useLocation, useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
|
import { showNotification } from '@mantine/notifications';
|
||||||
import { api } from '../../App';
|
import { api } from '../../App';
|
||||||
import { ApiEndpoints } from '../../enums/ApiEndpoints';
|
import { ApiEndpoints } from '../../enums/ApiEndpoints';
|
||||||
import {
|
import {
|
||||||
@ -44,26 +45,31 @@ export function AuthenticationForm() {
|
|||||||
setIsLoggingIn(true);
|
setIsLoggingIn(true);
|
||||||
|
|
||||||
if (classicLoginMode === true) {
|
if (classicLoginMode === true) {
|
||||||
doBasicLogin(
|
doBasicLogin(classicForm.values.username, classicForm.values.password)
|
||||||
classicForm.values.username,
|
.then(() => {
|
||||||
classicForm.values.password
|
setIsLoggingIn(false);
|
||||||
).then(() => {
|
|
||||||
setIsLoggingIn(false);
|
|
||||||
|
|
||||||
if (isLoggedIn()) {
|
if (isLoggedIn()) {
|
||||||
showLoginNotification({
|
showLoginNotification({
|
||||||
title: t`Login successful`,
|
title: t`Login successful`,
|
||||||
message: t`Logged in successfully`
|
message: t`Logged in successfully`
|
||||||
});
|
});
|
||||||
followRedirect(navigate, location?.state);
|
followRedirect(navigate, location?.state);
|
||||||
} else {
|
} else {
|
||||||
showLoginNotification({
|
showLoginNotification({
|
||||||
|
title: t`Login failed`,
|
||||||
|
message: t`Check your input and try again.`,
|
||||||
|
success: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
showNotification({
|
||||||
title: t`Login failed`,
|
title: t`Login failed`,
|
||||||
message: t`Check your input and try again.`,
|
message: t`Check your input and try again.`,
|
||||||
success: false
|
color: 'red'
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
doSimpleLogin(simpleForm.values.email).then((ret) => {
|
doSimpleLogin(simpleForm.values.email).then((ret) => {
|
||||||
setIsLoggingIn(false);
|
setIsLoggingIn(false);
|
||||||
|
@ -53,18 +53,24 @@ export default function RemoteComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sourceFile && functionName) {
|
if (sourceFile && functionName) {
|
||||||
findExternalPluginFunction(sourceFile, functionName).then((func) => {
|
findExternalPluginFunction(sourceFile, functionName)
|
||||||
if (func) {
|
.then((func) => {
|
||||||
try {
|
if (func) {
|
||||||
func(componentRef.current, context);
|
try {
|
||||||
setRenderingError('');
|
func(componentRef.current, context);
|
||||||
} catch (error) {
|
setRenderingError('');
|
||||||
setRenderingError(`${error}`);
|
} catch (error) {
|
||||||
|
setRenderingError(`${error}`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setRenderingError(`${sourceFile}:${functionName}`);
|
||||||
}
|
}
|
||||||
} else {
|
})
|
||||||
setRenderingError(`${sourceFile}:${functionName}`);
|
.catch((_error) => {
|
||||||
}
|
console.error(
|
||||||
});
|
`ERR: Failed to load remove plugin function: ${sourceFile}:${functionName}`
|
||||||
|
);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
setRenderingError(
|
setRenderingError(
|
||||||
`${t`Invalid source or function name`} - ${sourceFile}:${functionName}`
|
`${t`Invalid source or function name`} - ${sourceFile}:${functionName}`
|
||||||
|
@ -12,6 +12,7 @@ import type React from 'react';
|
|||||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
|
import { showNotification } from '@mantine/notifications';
|
||||||
import { api } from '../App';
|
import { api } from '../App';
|
||||||
import { Boundary } from '../components/Boundary';
|
import { Boundary } from '../components/Boundary';
|
||||||
import type { ApiFormFieldSet } from '../components/forms/fields/ApiFormField';
|
import type { ApiFormFieldSet } from '../components/forms/fields/ApiFormField';
|
||||||
@ -198,6 +199,15 @@ export function InvenTreeTable<T extends Record<string, any>>({
|
|||||||
setTableColumnNames(cacheKey)(names);
|
setTableColumnNames(cacheKey)(names);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
showNotification({
|
||||||
|
title: t`API Error`,
|
||||||
|
message: t`Failed to load table options`,
|
||||||
|
color: 'red'
|
||||||
|
});
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user