TIL
궁금점
Feign으로 부르는 메소드 호출에서는 404 가 내려오면 어떻게 될까? 어떻게 처리하나?
Feign 404
@FeignClient(decode404 = false) 의 경우
FeignClient annotation의 decode404 property는 false가 default 값이다. 해당 설정으로 404를 받아오는 경우에는 FeignException을 발생시킨다. Feign호출을 하였을 때 resource가 존재하지 않는 경우, 호출하는 쪽에서 404 NOT_FOUND에 대한 적절한 동작을 할 수 없게 된다.
@FeignClient(decode404 = true) 의 경우
decode404를 true로 설정하는 경우, Feign의 기본 decode 메소드가 java의 기본 type들을 빈 객체로 만들어서 내려준다. 아래는 지원하는 java type 들이다.
- Boolean --> false
- byte[] --> false
- Collection --> EmptyList
- Iterator --> EmptyIterator
- List --> EmptyList
- Map --> EmptyMap
- Set --> EmptySet
- Optional --> value가 없는 Optional
- Stream --> empty sequential stream
위의 타입에 해당하지 않는 값은 null을 반환한다.
// Feign.Util
public static Object emptyValueOf(Type type) {
return EMPTIES.getOrDefault(Types.getRawType(type), () -> null).get();
}
Kotlin 의 경우
decode404=true 값을 설정하게 된다면 nullable 한 return type을 설정해 줘야한다.
관련 github thread
https://github.com/OpenFeign/feign/issues/476
https://github.com/OpenFeign/feign/commit/24885fe9620ed620af43f4d2d6ffcfc82980e097#diff-b54b942c0c272042049c1fbdbe6084aa
반응형
'devlog > TIL' 카테고리의 다른 글
유용한 linux command 모음 (사실 나를 위한 포스트 | 계속 추가 중) (0) | 2020.08.25 |
---|---|
[TIL] jooq 잘 모르겠다 🤔 (0) | 2020.02.14 |
[TIB] spock으로 테스트를 짜고 있는데 (0) | 2020.02.13 |
[TIL] ExecutorService / Event Driven Programming / Bulk Insert / DiscriminatorValue / AuditingEntityListener (0) | 2019.11.20 |
It is currently in use by another Gradle instance (0) | 2019.11.13 |