Skip to content

Commit

Permalink
error 처리 수정
Browse files Browse the repository at this point in the history
error 처리 수정
  • Loading branch information
heedda authored May 6, 2024
2 parents ac640d5 + 5ea92f1 commit dc5682d
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 17 deletions.
7 changes: 5 additions & 2 deletions src/api/afterManage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {
ClubList,
Type,
} from "../type";
import { apiError } from "@/hook/errorHandling";
const { handleError } = apiError();
import apiError from "@/hook/errorHandling";

export const GetClubList = (club: string) => {
return useQuery<ClubList[]>({
Expand All @@ -21,6 +20,7 @@ export const GetClubList = (club: string) => {
};

export const FixStatus = () => {
const { handleError } = apiError();
return useMutation<void, Error, ChangeStatus[]>({
mutationFn: async (param) => {
try {
Expand All @@ -43,6 +43,7 @@ export const AllStudent = () => {
};

export const PostStudent = () => {
const { handleError } = apiError();
return useMutation<void, Error, { student_num: string }[]>({
mutationFn: async (param) => {
try {
Expand All @@ -65,6 +66,7 @@ export const GetAfterStudent = () => {
};

export const AfterStudentDelete = () => {
const { handleError } = apiError();
return useMutation<void, Error, { id: string }>({
mutationFn: async ({ id }) => {
try {
Expand All @@ -82,6 +84,7 @@ export const AfterStudentDelete = () => {
};

export const CheckStatus = () => {
const { handleError } = apiError();
return useMutation<void, Error, ChangeClub[]>({
mutationFn: async (param) => {
try {
Expand Down
5 changes: 3 additions & 2 deletions src/api/attendanceCheck/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useMutation, useQuery } from "@tanstack/react-query";
import { instance } from "..";
import { AttendanceChack, ClubList } from "../type";
import { apiError } from "@/hook/errorHandling";
const { handleError } = apiError();
import apiError from "@/hook/errorHandling";

export const GetStudentsAttendance = () => {
const { handleError } = apiError();
return useMutation<ClubList[], Error, { grade: number; class: number }>({
mutationFn: async (param) => {
try {
Expand All @@ -20,6 +20,7 @@ export const GetStudentsAttendance = () => {
};

export const AttendanceSave = () => {
const { handleError } = apiError();
return useMutation<void, Error, AttendanceChack[]>({
mutationFn: async (param) => {
try {
Expand Down
5 changes: 3 additions & 2 deletions src/api/bug/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useMutation, useQuery } from "@tanstack/react-query";
import { instance } from "..";
import { apiError } from "@/hook/errorHandling";
const { handleError } = apiError();
import apiError from "@/hook/errorHandling";

interface BugProp {
title: string;
Expand All @@ -10,6 +9,7 @@ interface BugProp {
}

export const BugPost = () => {
const { handleError } = apiError();
return useMutation<void, Error, BugProp>({
mutationFn: async (param) => {
try {
Expand All @@ -26,6 +26,7 @@ export const BugPost = () => {
};

export const BugImg = () => {
const { handleError } = apiError();
return useMutation<string, Error, { file: File }>({
mutationFn: async (param) => {
try {
Expand Down
5 changes: 3 additions & 2 deletions src/api/classChange/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useMutation, useQuery } from "@tanstack/react-query";
import { instance } from "..";
import { FloorClass, changeClass } from "../type";
import { apiError } from "@/hook/errorHandling";
const { handleError } = apiError();
import apiError from "@/hook/errorHandling";

export const AcceptClassChange = (floor: number) => {
return useQuery<FloorClass[]>({
Expand All @@ -17,6 +16,7 @@ export const AcceptClassChange = (floor: number) => {
};

export const AcceptClass = () => {
const { handleError } = apiError();
return useMutation<void, Error, { status: string; id: string[] }>({
mutationFn: async (param) => {
try {
Expand All @@ -32,6 +32,7 @@ export const AcceptClass = () => {
};

export const GetFloor = () => {
const { handleError } = apiError();
return useMutation<changeClass[], void, { floor: number }>({
mutationFn: async (param) => {
try {
Expand Down
10 changes: 4 additions & 6 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import axios, { AxiosError } from "axios";
import { cookie } from "@/util/auth";
import { apiError } from "@/hook/errorHandling";
const { handleError } = apiError();

const BASEURL = process.env.NEXT_PUBLIC_API_KEY;

Expand Down Expand Up @@ -65,16 +63,16 @@ instance.interceptors.response.use(
return axios.request(error.config);
}
} catch {
handleError(error);
throw error;
}
} else {
handleError(error);
throw error;
}
} else {
handleError(error);
throw error;
}
} else {
handleError(error);
throw error;
}
}
);
6 changes: 4 additions & 2 deletions src/api/outList/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useMutation, useQuery } from "@tanstack/react-query";
import { instance } from "..";
import { Accept, ClassProp, applicationOK, earlyReturnHome } from "../type";
import { apiError } from "@/hook/errorHandling";
const { handleError } = apiError();
import apiError from "@/hook/errorHandling";

export const Application = () => {
return useQuery<applicationOK[]>({
Expand All @@ -25,6 +24,7 @@ export const EarlyReturn = () => {
};

export const ReturnSchool = () => {
const { handleError } = apiError();
return useMutation<Error, void, { id: string }>({
mutationFn: async (param) => {
try {
Expand All @@ -40,6 +40,7 @@ export const ReturnSchool = () => {
};

export const GetClass = () => {
const { handleError } = apiError();
return useMutation<applicationOK[], Error, ClassProp>({
mutationFn: async (param: ClassProp) => {
try {
Expand All @@ -54,6 +55,7 @@ export const GetClass = () => {
});
};
export const OutAcceptApi = () => {
const { handleError } = apiError();
return useMutation<void, Error, Accept>({
mutationFn: async (param) => {
try {
Expand Down
4 changes: 3 additions & 1 deletion src/hook/errorHandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type HandleType = {
[key: string]: ErrorHandler | { [key: string]: ErrorHandler };
};

export const apiError = () => {
const apiError = () => {
const handle400: ErrorHandler = () => {
alert("400 잘못된 요청입니다");
};
Expand Down Expand Up @@ -67,3 +67,5 @@ export const apiError = () => {

return { handleError };
};

export default apiError;

0 comments on commit dc5682d

Please sign in to comment.