Skip to content

Commit

Permalink
fix: add error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nowgnuesLee committed Jan 21, 2025
1 parent 5d00863 commit 9c5a840
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
49 changes: 27 additions & 22 deletions react/src/components/KeypairResourcePolicySettingModal.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { convertBinarySizeUnit } from '../helper';
import {
MAX_CPU_QUOTA,
UNLIMITED_MAX_CONCURRENT_SESSIONS,
UNLIMITED_MAX_CONTAINERS_PER_SESSIONS,
} from '../helper/const-vars';
import { useSuspendedBackendaiClient } from '../hooks';
import { useResourceSlots, useResourceSlotsDetails } from '../hooks/backendai';
import { usePainKiller } from '../hooks/usePainKiller';
import AllowedHostNamesSelect from './AllowedHostNamesSelect';
import BAIModal, { BAIModalProps } from './BAIModal';
import DynamicUnitInputNumber from './DynamicUnitInputNumber';
Expand Down Expand Up @@ -56,6 +58,7 @@ const KeypairResourcePolicySettingModal: React.FC<
const { t } = useTranslation();
const { token } = theme.useToken();
const { message } = App.useApp();
const painKiller = usePainKiller();
const formRef = useRef<FormInstance>(null);
const [resourceSlots] = useResourceSlots();
const { mergedResourceSlots } = useResourceSlotsDetails();
Expand Down Expand Up @@ -218,17 +221,18 @@ const KeypairResourcePolicySettingModal: React.FC<
props: props as CreateKeyPairResourcePolicyInput,
},
onCompleted: (res, errors) => {
if (!res?.create_keypair_resource_policy?.ok) {
message.error(res?.create_keypair_resource_policy?.msg);
onRequestClose();
return;
}
if (errors && errors?.length > 0) {
const errorMsgList = _.map(errors, (error) => error.message);
for (const error of errorMsgList) {
message.error(error, 2.5);
if (!res?.create_keypair_resource_policy?.ok || errors) {
if (res.create_keypair_resource_policy?.msg) {
message.error(
painKiller.relieve(res.create_keypair_resource_policy.msg),
);
} else if (errors && errors.length > 0) {
// if res.create_keypair_resource_policy is null
errors.forEach((error) =>
message.error(painKiller.relieve(error.message), 2.5),
);
}
onRequestClose();
onRequestClose(false);
} else {
message.success(t('resourcePolicy.SuccessfullyCreated'));
onRequestClose(true);
Expand All @@ -245,19 +249,20 @@ const KeypairResourcePolicySettingModal: React.FC<
props: props as ModifyKeyPairResourcePolicyInput,
},
onCompleted: (res, errors) => {
if (!res?.modify_keypair_resource_policy?.ok) {
message.error(res?.modify_keypair_resource_policy?.msg);
onRequestClose();
return;
}
if (errors && errors?.length > 0) {
const errorMsgList = _.map(errors, (error) => error.message);
for (const error of errorMsgList) {
message.error(error, 2.5);
if (!res?.modify_keypair_resource_policy?.ok || errors) {
if (res.modify_keypair_resource_policy?.msg) {
message.error(
painKiller.relieve(res.modify_keypair_resource_policy.msg),
);
} else if (errors && errors.length > 0) {
// if res.create_keypair_resource_policy is null
errors.forEach((error) =>
message.error(painKiller.relieve(error.message), 2.5),
);
}
onRequestClose();
onRequestClose(false);
} else {
message.success(t('resourcePolicy.SuccessfullyUpdated'));
message.success(t('resourcePolicy.SuccessfullyCreated'));
onRequestClose(true);
}
},
Expand Down Expand Up @@ -354,7 +359,6 @@ const KeypairResourcePolicySettingModal: React.FC<
rules={[
{
validator(__, value) {
console.log(resourceSlotKey);
if (
_.includes(resourceSlotKey, 'mem') &&
value &&
Expand All @@ -381,6 +385,7 @@ const KeypairResourcePolicySettingModal: React.FC<
) : (
<InputNumber
min={0}
max={MAX_CPU_QUOTA}
step={
_.includes(resourceSlotKey, '.shares') ? 0.1 : 1
}
Expand Down
1 change: 1 addition & 0 deletions react/src/helper/const-vars.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const UNLIMITED_MAX_CONTAINERS_PER_SESSIONS = 1000000;
export const UNLIMITED_MAX_CONCURRENT_SESSIONS = 1000000;
export const SIGNED_32BIT_MAX_INT = Math.pow(2, 31) - 1;
export const MAX_CPU_QUOTA = 1e16;

0 comments on commit 9c5a840

Please sign in to comment.