Conversation
bb60182 to
dfbd1c8
Compare
Hank-Choi
left a comment
There was a problem hiding this comment.
제대론 안봤는데요
일단 테스트 깨지는 것 같고
또 응답에 유저 아이디 반환하면 유저 객체 반환하는 부분이 안보이네요
d93748d to
7301714
Compare
|
테스트는 고쳤고 유저 정보 넣는거 추가할게요 |
70bcb71 to
774bfa4
Compare
| } | ||
|
|
||
| val encodedJson = | ||
| withContext(Dispatchers.IO) { |
There was a problem hiding this comment.
이 부분에 왜 withContext를 썼는지, 그리고 왜 Dispatchers.IO를 썼는지 궁금하네
There was a problem hiding this comment.
비슷하게 해보니까
URLEncoder.encode 에서 블라킹이 발생할 수 있다고 하는데
그렇다고 IO Dispatcher에서 돌리는 것도 좀 이상하다고 생각합니다.
SeonghaeJo
left a comment
There was a problem hiding this comment.
아직은 코드만 봤는데 테스트를 조금 더 해볼게
| URLEncoder.encode( | ||
| ObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE).writeValueAsString(recentLectures), | ||
| "UTF-8", | ||
| ) |
There was a problem hiding this comment.
objectMapper는 dependency injection해서 써도 될 듯
| class ProxyException( | ||
| val statusCode: HttpStatusCode, | ||
| val errorBody: Map<String, Any?>, | ||
| ) : RuntimeException(ObjectMapper().writeValueAsString(errorBody)) |
There was a problem hiding this comment.
Exception 파일인데 ObjectMapper를 가져오는게 조금 어색해요
그냥 message 빼도 될 것 같은데요
어차피 Throwable.message 쓰는 경우 없을테니..
There was a problem hiding this comment.
그리고 이거 ev 서비스란 것도 명시해주세요
아마 이런식으로 프록시하는건 이게 마지막일거라서..
| if (throwable is ProxyException) { | ||
| exchange.response.statusCode = throwable.statusCode | ||
| exchange.response.headers.contentType = MediaType.APPLICATION_JSON | ||
| exchange.response.writeWith( | ||
| Mono.just( | ||
| exchange.response | ||
| .bufferFactory() | ||
| .wrap(objectMapper.writeValueAsBytes(throwable.errorBody)), | ||
| ), | ||
| ) | ||
| } else { | ||
| val errorBody: ErrorBody | ||
| val httpStatusCode: HttpStatusCode | ||
| when (throwable) { | ||
| is Snu4tException -> { | ||
| httpStatusCode = throwable.error.httpStatus | ||
| errorBody = makeErrorBody(throwable) | ||
| } | ||
|
|
||
| is ResponseStatusException -> { | ||
| httpStatusCode = throwable.statusCode | ||
| errorBody = | ||
| makeErrorBody( | ||
| Snu4tException( | ||
| errorMessage = throwable.body.title ?: ErrorType.DEFAULT_ERROR.errorMessage, | ||
| ), | ||
| ) | ||
| } | ||
|
|
||
| else -> { | ||
| log.error(throwable.message, throwable) | ||
| httpStatusCode = HttpStatus.INTERNAL_SERVER_ERROR | ||
| errorBody = makeErrorBody(Snu4tException()) | ||
| } | ||
| } |
There was a problem hiding this comment.
기존 when 이 있는데 depth가 더 들어가서 한눈에 안들어오네요
There was a problem hiding this comment.
| if (throwable is ProxyException) { | |
| exchange.response.statusCode = throwable.statusCode | |
| exchange.response.headers.contentType = MediaType.APPLICATION_JSON | |
| exchange.response.writeWith( | |
| Mono.just( | |
| exchange.response | |
| .bufferFactory() | |
| .wrap(objectMapper.writeValueAsBytes(throwable.errorBody)), | |
| ), | |
| ) | |
| } else { | |
| val errorBody: ErrorBody | |
| val httpStatusCode: HttpStatusCode | |
| when (throwable) { | |
| is Snu4tException -> { | |
| httpStatusCode = throwable.error.httpStatus | |
| errorBody = makeErrorBody(throwable) | |
| } | |
| is ResponseStatusException -> { | |
| httpStatusCode = throwable.statusCode | |
| errorBody = | |
| makeErrorBody( | |
| Snu4tException( | |
| errorMessage = throwable.body.title ?: ErrorType.DEFAULT_ERROR.errorMessage, | |
| ), | |
| ) | |
| } | |
| else -> { | |
| log.error(throwable.message, throwable) | |
| httpStatusCode = HttpStatus.INTERNAL_SERVER_ERROR | |
| errorBody = makeErrorBody(Snu4tException()) | |
| } | |
| } | |
| val errorBody: Any | |
| val httpStatusCode: HttpStatusCode | |
| when (throwable) { | |
| is ProxyException -> { | |
| httpStatusCode = throwable.statusCode | |
| errorBody = throwable.errorBody | |
| } | |
| is Snu4tException -> { | |
| httpStatusCode = throwable.error.httpStatus | |
| errorBody = makeErrorBody(throwable) | |
| } | |
| is ResponseStatusException -> { | |
| httpStatusCode = throwable.statusCode | |
| errorBody = | |
| makeErrorBody( | |
| Snu4tException(errorMessage = throwable.body.title ?: ErrorType.DEFAULT_ERROR.errorMessage), | |
| ) | |
| } | |
| else -> { | |
| log.error(throwable.message, throwable) | |
| httpStatusCode = HttpStatus.INTERNAL_SERVER_ERROR | |
| errorBody = makeErrorBody(Snu4tException()) | |
| } | |
| } |
그냥 이렇게 하면 안되나요
|
|
||
| return snuttEvWebClient.get() | ||
| .uri { builder -> | ||
| UriComponentsBuilder.fromUri(builder.build()) |
| } | ||
|
|
||
| val encodedJson = | ||
| withContext(Dispatchers.IO) { |
There was a problem hiding this comment.
비슷하게 해보니까
URLEncoder.encode 에서 블라킹이 발생할 수 있다고 하는데
그렇다고 IO Dispatcher에서 돌리는 것도 좀 이상하다고 생각합니다.
| val encodedJson = | ||
| withContext(Dispatchers.IO) { | ||
| URLEncoder.encode( | ||
| ObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE).writeValueAsString(recentLectures), | ||
| "UTF-8", | ||
| ) | ||
| } | ||
|
|
||
| return snuttEvWebClient.get() | ||
| .uri { builder -> | ||
| UriComponentsBuilder.fromUri(builder.build()) | ||
| .path("/v1/users/me/lectures/latest") | ||
| .queryParam("snutt_lecture_info", encodedJson) | ||
| .queryParams(requestQueryParams) | ||
| .build(true).toUri() | ||
| } |
There was a problem hiding this comment.
webclient uri 빌더 문법 저도 싫어하는데
Encoder 가 dispatcher에 쌓여있는게 좀 더 싫어서 아래 코드가 나아보입니다.
| val encodedJson = | |
| withContext(Dispatchers.IO) { | |
| URLEncoder.encode( | |
| ObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE).writeValueAsString(recentLectures), | |
| "UTF-8", | |
| ) | |
| } | |
| return snuttEvWebClient.get() | |
| .uri { builder -> | |
| UriComponentsBuilder.fromUri(builder.build()) | |
| .path("/v1/users/me/lectures/latest") | |
| .queryParam("snutt_lecture_info", encodedJson) | |
| .queryParams(requestQueryParams) | |
| .build(true).toUri() | |
| } | |
| val lectureInfoParam = ObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE).writeValueAsString(recentLectures) | |
| return snuttEvWebClient.get() | |
| .uri { builder -> | |
| builder | |
| .path("/v1/users/me/lectures/latest") | |
| .queryParam("snutt_lecture_info", "{lectureInfoParam}") | |
| .queryParams(requestQueryParams) | |
| .build(lectureInfoParam) | |
| } |
Hank-Choi
left a comment
There was a problem hiding this comment.
LGTM
나중엔 여기서 모든 path를 관리하는 것도 고려해보죠
| data class EvUserDto( | ||
| val id: String?, | ||
| val email: String?, | ||
| val local_id: String?, |
There was a problem hiding this comment.
네이밍 통일하시죠 JsonProperty로 json에만 스네이크케이스면 좋겠습니다.
ev-service 프록시하는 부분을 기존에 쓰던 SnuttEvWebClient 사용해서 마이그레이션 진행했습니다
하면서 생긴 몇가지 문제가 있어서 공유드려요
/v1/users/me/lectures/latest의 경우 query parameter에 json을 넣게 되어 있는데 이게 기본적으로는 스프링이 { 같은 특수문자를 변수 바꿔넣는 자리로 인식해서 이건 UriComponentsBuilder로 우회를 했어요테스트 안돌아가서 다시 볼게요