diff --git a/src/api/my/updatePCName.js b/src/api/my/updatePCName.js index b2a4d9e6e5faf70381abf7f4a57f16fb787b3304..f81d155ab9a09060fd44454f19d5e20fc61fe03f 100644 --- a/src/api/my/updatePCName.js +++ b/src/api/my/updatePCName.js @@ -1,56 +1,41 @@ 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 { - message: "인증되지 않은 요청입니다", - statusCode: 401, - data: {} + const unauthorizedError = new Error("인증되지 않은 요청입니다"); + unauthorizedError.response = { + data: { + message: "인증되지 않은 요청입니다", + statusCode: 401, + data: {} + } }; + throw unauthorizedError; } // 400 Bad Request 에러 처리 if (error.response?.status === 400) { - throw { - message: "잘못된 요청입니다", - statusCode: 400, + const badRequestError = new Error("잘못된 요청입니다"); + badRequestError.response = { data: { - error: "이름은 필수 입력값입니다" + message: "잘못된 요청입니다", + statusCode: 400, + data: { + error: "이름은 필수 입력값입니다" + } } }; + throw badRequestError; } // 기타 에러는 그대로 전달