728x90

 

 

🚨  에러 발생 

유저 정보를 JSON 형태로 바디에 담아 AWS RDS DB에 보내는 POST API를 작성 중에 지속해서 4000번 코드 에러가 발생하였다.

 

 

 

 

DB에 존재하는 닉네임이나 이메일을 넣으면 정상적으로 지정한 Error_Status가 뜨는 걸 봐서 코드 문제나 DB칼럼명 실수는 아닌 것 같았다. 

 

 

 

 

 

예상 문제 지점

//POST
    public TestPostUserRes createUser(TestPostUserReq testpostUserReq) throws BaseException {
        //닉네임 중복
        if(userProvider.checkNickname(testpostUserReq.getUserNickname()) ==1){
            throw new BaseException(POST_USERS_EXISTS_NICKNAME);
        }

        //이메일 중복
        if(userProvider.checkEmail(testpostUserReq.getUserEmail()) ==1){
            throw new BaseException(POST_USERS_EXISTS_EMAIL);
        }


        String pwd;
        try{
            //암호화
            pwd = new AES128(Secret.USER_INFO_PASSWORD_KEY).encrypt(testpostUserReq.getUserPassword());
            testpostUserReq.setUserPassword(pwd);
        } catch (Exception ignored) {
            throw new BaseException(PASSWORD_ENCRYPTION_ERROR);
        }

        try{
            int userId = userDao.createUser(testpostUserReq);
           // jwt 발급.
//            String jwt = jwtService.createJwt(userId);
            return new TestPostUserRes(userId);
        } catch (Exception exception) {
            throw new BaseException(DATABASE_ERROR);
        }
    }

 

DB에 존재하는 닉네임이나 이메일을 넣으면 정상적으로 지정한 Error_Status가 뜨는 걸 봐서 코드 문제나 DB컬럼명 실수는 아닌 것 같았다. 그래서 에러 로그를 찬찬히 살펴보니 Data truncation: Data too long for column 'ID' at row 1; nested exception is com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'ID' at row 1] with root cause  

 

컬럼 중 ID라는 칼럼의 데이터 값이 너무 길다는 오류 문구를 찾았다. 

그래서 DB컬럼 조건을 봤더니 필자가 varchar를 10으로 막아놓고 ID를 무려 12글자나 넣으려고 했던 것을 알게 됐다.

 

오늘도 디버깅의 중요성을 깨닫고 간다.

또한 도움을 준 새벽에도 도움을 주신 리오 님에게 감사하다는 인사를 전한다. 

 

 

 

 

 

 

👌  에러 해결

 

 

JSON 바디의 ID 컬럼의 value길이를 조절해 POST 했더니 해결

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

복사했습니다!