Skip to content
Snippets Groups Projects
Commit 85ced969 authored by 정원제's avatar 정원제 :guitar:
Browse files

chore: eslint에 맞게 error를 throw하게 변경

parent 54172dba
No related branches found
No related tags found
No related merge requests found
Pipeline #10795 passed
import axios from '../axios'; import axios from '../axios';
const updatePCName = async (pcId, newName) => { const updatePCName = async (pcId, newName) => {
console.log(pcId, newName);
try { try {
// 입력값 검증
if (!newName || !newName.trim()) {
throw {
response: {
data: {
message: "잘못된 요청입니다",
statusCode: 400,
data: {
error: "이름은 필수 입력값입니다"
}
}
}
};
}
const response = await axios.patch(`/my/pc/${pcId}/name`, { const response = await axios.patch(`/my/pc/${pcId}/name`, {
name: newName.trim() name: newName.trim()
}); });
// 성공 응답 형식에 맞춤 return response.data;
return {
message: "PC 이름이 성공적으로 변경되었습니다",
statusCode: 200,
data: {
id: pcId,
name: newName,
updatedAt: new Date().toISOString()
}
};
} catch (error) { } catch (error) {
// 401 Unauthorized 에러 처리 // 401 Unauthorized 에러 처리
if (error.response?.status === 401) { if (error.response?.status === 401) {
throw { const unauthorizedError = new Error("인증되지 않은 요청입니다");
unauthorizedError.response = {
data: {
message: "인증되지 않은 요청입니다", message: "인증되지 않은 요청입니다",
statusCode: 401, statusCode: 401,
data: {} data: {}
}
}; };
throw unauthorizedError;
} }
// 400 Bad Request 에러 처리 // 400 Bad Request 에러 처리
if (error.response?.status === 400) { if (error.response?.status === 400) {
throw { const badRequestError = new Error("잘못된 요청입니다");
badRequestError.response = {
data: {
message: "잘못된 요청입니다", message: "잘못된 요청입니다",
statusCode: 400, statusCode: 400,
data: { data: {
error: "이름은 필수 입력값입니다" error: "이름은 필수 입력값입니다"
} }
}
}; };
throw badRequestError;
} }
// 기타 에러는 그대로 전달 // 기타 에러는 그대로 전달
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment