feign-vnderror-spring-cloud-starter

Spring Cloud Netflix Feign vnd.error decoder

Лицензия

Лицензия

Категории

Категории

Feign Сеть HTTP Clients
Группа

Группа

com.github.jmnarloch
Идентификатор

Идентификатор

feign-vnderror-spring-cloud-starter
Последняя версия

Последняя версия

1.2.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

feign-vnderror-spring-cloud-starter
Spring Cloud Netflix Feign vnd.error decoder
Ссылка на сайт

Ссылка на сайт

https://github.com/jmnarloch/feign-vnderror-spring-cloud-starter
Система контроля версий

Система контроля версий

https://github.com/jmnarloch/feign-vnderror-spring-cloud-starter.git

Скачать feign-vnderror-spring-cloud-starter

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.github.jmnarloch/feign-vnderror-spring-cloud-starter/ -->
<dependency>
    <groupId>com.github.jmnarloch</groupId>
    <artifactId>feign-vnderror-spring-cloud-starter</artifactId>
    <version>1.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.jmnarloch/feign-vnderror-spring-cloud-starter/
implementation 'com.github.jmnarloch:feign-vnderror-spring-cloud-starter:1.2.0'
// https://jarcasting.com/artifacts/com.github.jmnarloch/feign-vnderror-spring-cloud-starter/
implementation ("com.github.jmnarloch:feign-vnderror-spring-cloud-starter:1.2.0")
'com.github.jmnarloch:feign-vnderror-spring-cloud-starter:jar:1.2.0'
<dependency org="com.github.jmnarloch" name="feign-vnderror-spring-cloud-starter" rev="1.2.0">
  <artifact name="feign-vnderror-spring-cloud-starter" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.jmnarloch', module='feign-vnderror-spring-cloud-starter', version='1.2.0')
)
libraryDependencies += "com.github.jmnarloch" % "feign-vnderror-spring-cloud-starter" % "1.2.0"
[com.github.jmnarloch/feign-vnderror-spring-cloud-starter "1.2.0"]

Зависимости

compile (3)

Идентификатор библиотеки Тип Версия
org.springframework.cloud : spring-cloud-starter-feign jar 1.0.3.RELEASE
commons-io : commons-io jar 2.4
org.springframework.boot : spring-boot-starter-hateoas jar 1.2.5.RELEASE

test (3)

Идентификатор библиотеки Тип Версия
org.mockito : mockito-all jar 1.10.19
junit : junit jar 4.12
org.springframework.boot : spring-boot-starter-test jar 1.2.5.RELEASE

Модули Проекта

Данный проект не имеет модулей.

Spring Cloud Netflix Feign vnd.error decoder

A custom error decoder for Netflix Feign that will unmarshall vnd.error.

Build Status Coverage Status

Features

A custom Feign ErrorDecoder capable of handling JSON vnd.error responses.

Setup

Add the Spring Cloud starter to your project:

<dependency>
  <groupId>com.github.jmnarloch</groupId>
  <artifactId>feign-vnderror-spring-cloud-starter</artifactId>
  <version>1.2.0</version>
</dependency>

Usage

First on server side make sure that your exception handling logic will return VndErrors (this is part of Spring Hateoas project). You can accomplish that by registering custom @ExceptionHandler in your application

@ExceptionHandler
ResponseEntity<VndErrors> someExceptionHandler(SomeException e) {

    String logref = UUID.randomUUID();
    
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setContentType(MediaType.parseMediaType("application/vnd.error+json"));
    return new ResponseEntity<>(new VndErrors(logref, e.getMessage()), httpHeaders, HttpStatus.INTERNAL_SERVER_ERROR);
}

Place it in your @Controller or @ControllerAdvice annotated beans. You can populate the logref with some meaningful identifier that afterwards could be used during log analysis. Generally it could be a good idea to add HandlerInterceptor to populate request scoped identifier on preHandle().

The error decoding happens base on content type matching so it is crucial to return application/vnd.error+json as response content type.

You use your Feign clients in the same manner as in any other cases, the only difference is that whenever a client call will end with vnd.error you should expect VndErrorException instead of FeignException.

Example:

try {

    feignClient.operation();    
} catch (VndErrorException exc) {
    ...
}

The VndErrorException makes very convenient to passthrough exceptions, if you call remote service from a web application you can register @ExceptionHandler and return the original vnd.error retrieved from the VndErrorException.

Properties

feign.vnderror.enabled=true # whether to enable the vnd error decoder, true by default

Migration to 1.2.x

The VndErrorException has been reworked to include extra request information like http status, http headers and response body, replacing the existing exception constructors.

Also effort has been made to include the exception type directly in Spring HATEOAS.

License

Apache 2.0

Версии библиотеки

Версия
1.2.0
1.1.1
1.1.0
1.0.1
1.0.0