error-handling

Small library for error handling in spring webflux based microservices

Лицензия

Лицензия

Категории

Категории

IDE Инструменты разработки
Группа

Группа

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

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

error-handling
Последняя версия

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

0.2.1
Дата

Дата

Тип

Тип

jar
Описание

Описание

error-handling
Small library for error handling in spring webflux based microservices
Ссылка на сайт

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

https://github.com/acidelk/error-handling
Система контроля версий

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

https://github.com/acidelk/error-handling

Скачать error-handling

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

<!-- https://jarcasting.com/artifacts/com.github.acidelk/error-handling/ -->
<dependency>
    <groupId>com.github.acidelk</groupId>
    <artifactId>error-handling</artifactId>
    <version>0.2.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.acidelk/error-handling/
implementation 'com.github.acidelk:error-handling:0.2.1'
// https://jarcasting.com/artifacts/com.github.acidelk/error-handling/
implementation ("com.github.acidelk:error-handling:0.2.1")
'com.github.acidelk:error-handling:jar:0.2.1'
<dependency org="com.github.acidelk" name="error-handling" rev="0.2.1">
  <artifact name="error-handling" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.acidelk', module='error-handling', version='0.2.1')
)
libraryDependencies += "com.github.acidelk" % "error-handling" % "0.2.1"
[com.github.acidelk/error-handling "0.2.1"]

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

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

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

Spring boot starter for error handling in webflux microservices

Codacy Badge Build Status Maven Central

This starter handle all exceptions and log their.

What response model

{
    "error": {
        "code": -1,
        "message": "Something went wrong"
        "errorClass": "SomethingException",
        "serviceName": "my-best-api"
    }
}

How to use

build.gradle

dependencies {
    implementation 'com.github.acidelk:error-handling:{version}'
}

How can i customise handlers for my exceptions

@Configuration
public class ErrorHandlerConfiguration {

  @Bean
  public DefaultExceptionConverter defaultExceptionConverter(
      @Value("${spring.application.name}") String application
  ) {
    return new DefaultExceptionConverter(application)
        .withHandler(HttpUnknownException.class, this::handleUnknownException)
        .withDefaultHandler(this::handleDefaultException);
  }

  private ErrorResponse handleDefaultException(Exception e) {
    return new ErrorResponse(HttpStatus.I_AM_A_TEAPOT, -1, e.getMessage(), e.getClass().getSimpleName());
  }

  private ErrorResponse handleUnknownException(Exception e) {
    return ((HttpUnknownException) e).getErrorResponse();
  }
}

Create simple exception using ServiceException

@Getter
@ToString
public class DifferentChecksumException extends ServiceException {

  public DifferentChecksumException(String msg) {
    super(HttpStatus.NOT_FOUND, 100, msg);
  }

}

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

Версия
0.2.1
0.2.0
0.1.0