본문 바로가기

전체 글136

[Spring] 유니크 키 제약사항을 위반한 경우 HTTP 상태 코드 회원가입 시나리오로 예를들면 사용자가 입력한 아이디를 '아이디 중복확인' 버튼을 통해 중복체크 API 호출 이때 아이디가 중복된 상태라면 Response로 어떠한 상태 코드를 반환해야 할까? 기존에는 409 Conflict(원본과 현재 요청이 충돌)를 사용했지만 422 Unprocessable Entity(요청은 정확하게 이루어졌지만 처리할 수 없음)가 더 적절한 상태코드인것 같다. 출처 : https://stackoverflow.com/questions/25015592/whats-the-best-return-code-for-unique-violations What's the best return code for "@unique" violations? I'm working on a RESTful web .. 2023. 2. 1.
[Spring] 2개 이상의 유니크 키를 분리하여 예외처리 하기 @Entity @Table(uniqueConstraints = { @UniqueConstraint(name = "UC_email", columnNames = { "email" } ), @UniqueConstraint(name = "UC_username", columnNames = { "userName" } ) }) public User myFancyServiceMethod(...) { try { // do your stuff here return userRepository.save( user ); } catch( ConstraintViolationException e ) { if ( isExceptionUniqueConstraintFor( "UC_email" ) ) { throw new EmailAddr.. 2023. 1. 31.
[Django] migrate 시 no such table 에러 발생하는 경우 python manage.py makemigrations python manage.py migrate 위와 같은 명령어를 통해 migrate가 불가능할 경우 아래 명령어를 통해 싱크를 맞춰주면 된다. manage.py migrate --run-syncdb ref : https://stackoverflow.com/questions/34548768/no-such-table-exception 2023. 1. 19.
[Spring] @Transactional 롤백 기능 이용하기 @Transactional(rollbackFor = XYZException.class) 괄호 안에 롤백을 수행할 익셉션을 명시해주면 된다. ref : https://stackoverflow.com/questions/62887614/how-to-do-rollback-with-transactional-annotation 2023. 1. 18.