Skip to content

Commit

Permalink
Add axios error judge
Browse files Browse the repository at this point in the history
  • Loading branch information
momom-i committed Mar 12, 2022
1 parent 5d77960 commit fe3fa63
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions web/api/v1/node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { V1Node, V1NodeList } from "@kubernetes/client-node";
import { k8sInstance } from "@/api/v1/index";
import axios from "axios";

export const applyNode = async (req: V1Node, onError: (_: string) => void) => {
try {
Expand All @@ -14,12 +15,11 @@ export const applyNode = async (req: V1Node, onError: (_: string) => void) => {
);
return res.data;
} catch (e: any) {
try {
if (axios.isAxiosError(e) && e.response && e.response.status === 404) {
const res = await createNode(req, onError);
return res;
} catch (e: any) {
onError(e);
}
onError(e);
}
};

Expand Down
6 changes: 3 additions & 3 deletions web/api/v1/pod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { V1Pod, V1PodList } from "@kubernetes/client-node";
import { k8sInstance, namespaceURL } from "@/api/v1/index";
import axios from "axios";

export const applyPod = async (req: V1Pod, onError: (_: string) => void) => {
try {
Expand All @@ -14,12 +15,11 @@ export const applyPod = async (req: V1Pod, onError: (_: string) => void) => {
);
return res.data;
} catch (e: any) {
try {
if (axios.isAxiosError(e) && e.response && e.response.status === 404) {
const res = await createPod(req, onError);
return res;
} catch (e: any) {
onError(e);
}
onError(e);
}
};

Expand Down
6 changes: 3 additions & 3 deletions web/api/v1/priorityclass.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { V1PriorityClass, V1PriorityClassList } from "@kubernetes/client-node";
import { k8sSchedulingInstance } from "@/api/v1/index";
import axios from "axios";

export const applyPriorityClass = async (
req: V1PriorityClass,
Expand All @@ -17,12 +18,11 @@ export const applyPriorityClass = async (
);
return res.data;
} catch (e: any) {
try {
if (axios.isAxiosError(e) && e.response && e.response.status === 404) {
const res = await createPriorityClass(req, onError);
return res;
} catch (e: any) {
onError(e);
}
onError(e);
}
};

Expand Down
6 changes: 3 additions & 3 deletions web/api/v1/pv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
V1PersistentVolumeList,
} from "@kubernetes/client-node";
import { k8sInstance } from "@/api/v1/index";
import axios from "axios";

export const applyPersistentVolume = async (
req: V1PersistentVolume,
Expand All @@ -20,12 +21,11 @@ export const applyPersistentVolume = async (
);
return res.data;
} catch (e: any) {
try {
if (axios.isAxiosError(e) && e.response && e.response.status === 404) {
const res = await createPersistentvolumes(req, onError);
return res;
} catch (e: any) {
onError(e);
}
onError(e);
}
};

Expand Down
6 changes: 3 additions & 3 deletions web/api/v1/pvc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
V1PersistentVolumeClaimList,
} from "@kubernetes/client-node";
import { k8sInstance, namespaceURL } from "@/api/v1/index";
import axios from "axios";

export const applyPersistentVolumeClaim = async (
req: V1PersistentVolumeClaim,
Expand All @@ -21,12 +22,11 @@ export const applyPersistentVolumeClaim = async (
);
return res.data;
} catch (e: any) {
try {
if (axios.isAxiosError(e) && e.response && e.response.status === 404) {
const res = await createPersistentVolumeClaim(req, onError);
return res;
} catch (e: any) {
onError(e);
}
onError(e);
}
};

Expand Down
6 changes: 3 additions & 3 deletions web/api/v1/storageclass.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { V1StorageClass, V1StorageClassList } from "@kubernetes/client-node";
import { k8sStorageInstance } from "@/api/v1/index";
import axios from "axios";

export const applyStorageClass = async (
req: V1StorageClass,
Expand All @@ -17,12 +18,11 @@ export const applyStorageClass = async (
);
return res.data;
} catch (e: any) {
try {
if (axios.isAxiosError(e) && e.response && e.response.status === 404) {
const res = await createStorageclasses(req, onError);
return res;
} catch (e: any) {
onError(e);
}
onError(e);
}
};

Expand Down

0 comments on commit fe3fa63

Please sign in to comment.