error-handling

Small library for error handling in spring webflux based microservices

License

License

Categories

Categories

IDE Development Tools
GroupId

GroupId

com.github.acidelk
ArtifactId

ArtifactId

error-handling
Last Version

Last Version

0.2.1
Release Date

Release Date

Type

Type

jar
Description

Description

error-handling
Small library for error handling in spring webflux based microservices
Project URL

Project URL

https://github.com/acidelk/error-handling
Source Code Management

Source Code Management

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

Download error-handling

How to add to project

<!-- 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"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

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);
  }

}

Versions

Version
0.2.1
0.2.0
0.1.0