Skip to content
Snippets Groups Projects
Commit 85ced969 authored by 정원제's avatar 정원제 🎸
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';
const updatePCName = async (pcId, newName) => {
console.log(pcId, newName);
try {
// 입력값 검증
if (!newName || !newName.trim()) {
throw {
response: {
data: {
message: "잘못된 요청입니다",
statusCode: 400,
data: {
error: "이름은 필수 입력값입니다"
}
}
}
};
}
const response = await axios.patch(`/my/pc/${pcId}/name`, {
name: newName.trim()
});
// 성공 응답 형식에 맞춤
return {
message: "PC 이름이 성공적으로 변경되었습니다",
statusCode: 200,
data: {
id: pcId,
name: newName,
updatedAt: new Date().toISOString()
}
};
return response.data;
} catch (error) {
// 401 Unauthorized 에러 처리
if (error.response?.status === 401) {
throw {
const unauthorizedError = new Error("인증되지 않은 요청입니다");
unauthorizedError.response = {
data: {
message: "인증되지 않은 요청입니다",
statusCode: 401,
data: {}
}
};
throw unauthorizedError;
}
// 400 Bad Request 에러 처리
if (error.response?.status === 400) {
throw {
const badRequestError = new Error("잘못된 요청입니다");
badRequestError.response = {
data: {
message: "잘못된 요청입니다",
statusCode: 400,
data: {
error: "이름은 필수 입력값입니다"
}
}
};
throw badRequestError;
}
// 기타 에러는 그대로 전달
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment