mirror of
https://github.com/inventree/InvenTree.git
synced 2026-09-27 14:16:02 +00:00
Improved API error handling (#12884)
* Improved API error handling * Remove comment * Fixes for playwright
This commit is contained in:
@@ -26,6 +26,15 @@ export function extractErrorMessage({
|
|||||||
error_data['non_field_errors'];
|
error_data['non_field_errors'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fallback to 'errors' array
|
||||||
|
if (
|
||||||
|
!message &&
|
||||||
|
Array.isArray(error_data?.errors) &&
|
||||||
|
error_data.errors.length > 0
|
||||||
|
) {
|
||||||
|
message = error_data.errors[0].message ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
// No message? Look at the response status codes
|
// No message? Look at the response status codes
|
||||||
if (!message) {
|
if (!message) {
|
||||||
const status = error.status ?? error.response?.status ?? null;
|
const status = error.status ?? error.response?.status ?? null;
|
||||||
@@ -47,6 +56,9 @@ export function extractErrorMessage({
|
|||||||
case 405:
|
case 405:
|
||||||
message = t`Method not allowed`;
|
message = t`Method not allowed`;
|
||||||
break;
|
break;
|
||||||
|
case 409:
|
||||||
|
message = t`Conflict`;
|
||||||
|
break;
|
||||||
case 500:
|
case 500:
|
||||||
message = t`Internal server error`;
|
message = t`Internal server error`;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import { useNavigate } from 'react-router-dom';
|
|||||||
import { useShallow } from 'zustand/react/shallow';
|
import { useShallow } from 'zustand/react/shallow';
|
||||||
import { api, queryClient } from '../../../../App';
|
import { api, queryClient } from '../../../../App';
|
||||||
import { authApi, doLogout } from '../../../../functions/auth';
|
import { authApi, doLogout } from '../../../../functions/auth';
|
||||||
|
import { showApiErrorMessage } from '../../../../functions/notifications';
|
||||||
import { useServerApiState } from '../../../../states/ServerApiState';
|
import { useServerApiState } from '../../../../states/ServerApiState';
|
||||||
import { useGlobalSettingsState } from '../../../../states/SettingsStates';
|
import { useGlobalSettingsState } from '../../../../states/SettingsStates';
|
||||||
import { QrRegistrationForm } from './QrRegistrationForm';
|
import { QrRegistrationForm } from './QrRegistrationForm';
|
||||||
@@ -475,12 +476,11 @@ function RegisterTOTPModal({
|
|||||||
setSecret(error.response?.data?.meta?.secret ?? '');
|
setSecret(error.response?.data?.meta?.secret ?? '');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// Any other error is unexpected
|
showApiErrorMessage({
|
||||||
showNotification({
|
error: error,
|
||||||
title: t`Error Fetching TOTP Registration`,
|
title: t`Error Fetching TOTP Registration`
|
||||||
message: t`An unexpected error occurred while fetching TOTP registration data.`,
|
|
||||||
color: 'red'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -484,6 +484,11 @@ test('Stock - Return Items', async ({ browser }) => {
|
|||||||
|
|
||||||
// Location detail
|
// Location detail
|
||||||
await navigate(page, 'stock/item/1253');
|
await navigate(page, 'stock/item/1253');
|
||||||
|
|
||||||
|
// Allow some settling time for this page
|
||||||
|
await page.waitForLoadState('networkidle');
|
||||||
|
await page.waitForTimeout(100);
|
||||||
|
|
||||||
await page
|
await page
|
||||||
.getByRole('button', { name: 'action-menu-stock-operations' })
|
.getByRole('button', { name: 'action-menu-stock-operations' })
|
||||||
.click();
|
.click();
|
||||||
|
|||||||
@@ -444,6 +444,9 @@ test('Settings - Admin - Parameter', async ({ browser }) => {
|
|||||||
await page.getByRole('cell', { name: 'Animals', exact: true }).waitFor();
|
await page.getByRole('cell', { name: 'Animals', exact: true }).waitFor();
|
||||||
await page.getByText('Various animals and descriptions thereof').waitFor();
|
await page.getByText('Various animals and descriptions thereof').waitFor();
|
||||||
|
|
||||||
|
await page.waitForLoadState('networkidle');
|
||||||
|
await page.waitForTimeout(250);
|
||||||
|
|
||||||
// Clean old list data if exists
|
// Clean old list data if exists
|
||||||
await page
|
await page
|
||||||
.getByRole('cell', { name: 'some list' })
|
.getByRole('cell', { name: 'some list' })
|
||||||
@@ -538,6 +541,7 @@ test('Settings - Admin - Parameter', async ({ browser }) => {
|
|||||||
})
|
})
|
||||||
.click();
|
.click();
|
||||||
|
|
||||||
|
await page.waitForLoadState('networkidle');
|
||||||
await page.waitForTimeout(500);
|
await page.waitForTimeout(500);
|
||||||
|
|
||||||
await page.getByText('Add Parameter').waitFor();
|
await page.getByText('Add Parameter').waitFor();
|
||||||
|
|||||||
Reference in New Issue
Block a user