Skip to content

Comments

Simplify gRPC Exception Handling#351

Merged
dsyer merged 2 commits intospring-projects:mainfrom
o-shevchenko:gh-350
Jan 21, 2026
Merged

Simplify gRPC Exception Handling#351
dsyer merged 2 commits intospring-projects:mainfrom
o-shevchenko:gh-350

Conversation

@o-shevchenko
Copy link
Contributor

Introduce annotation-based exception handling for gRPC services

This allows simplified exception handling:

@GrpcAdvice
class MyExceptionHandler {
    @GrpcExceptionHandler
    fun handle(ex: TimeoutException): Status {
        return Status.DEADLINE_EXCEEDED.withDescription(ex.message)
    }
}

Signed-off-by: Oleksandr Shevchenko shevchenko.olexandr96@gmail.com

Inspired and heavily relies on https://github.com/grpc-ecosystem/grpc-spring/blob/master/grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/advice/GrpcExceptionHandler.java#L69

[resolves #350]

@dsyer
Copy link
Member

dsyer commented Jan 20, 2026

The import order requirements from our checkstyle checks are annoyingly difficult to get right. I wish we didn't do it, but most Spring projects do it now to cut down on whitespace changes. You can get it right by looking at similar classes and copying the order. This one so far looks easy - you just need a blank line before the springframework imports.

Introduce annotation-based exception handling for gRPC services,
similar to Spring MVC's @ControllerAdvice and @ExceptionHandler.

This allows simplified exception handling:

@GrpcAdvice
class MyExceptionHandler {
    @GrpcExceptionHandler
    fun handle(ex: TimeoutException): Status {
        return Status.DEADLINE_EXCEEDED.withDescription(ex.message)
    }
}

Signed-off-by: Oleksandr Shevchenko <oleksandr.shevchenko@datarobot.com>

[resolves spring-projects#350]
@o-shevchenko
Copy link
Contributor Author

The import order requirements from our checkstyle checks are annoyingly difficult to get right. I wish we didn't do it, but most Spring projects do it now to cut down on whitespace changes. You can get it right by looking at similar classes and copying the order. This one so far looks easy - you just need a blank line before the springframework imports.

Thanks @dsyer . I've pushed style changes

@dsyer
Copy link
Member

dsyer commented Jan 20, 2026

If you build locally with Java 25 you should get the same error I guess.

Signed-off-by: Oleksandr Shevchenko <oleksandr.shevchenko@datarobot.com>
@dsyer
Copy link
Member

dsyer commented Jan 20, 2026

All good thanks. It’ll get merged once we branch off to 1.1.x.

@dsyer dsyer added the enhancement New feature or request label Jan 20, 2026
@dsyer dsyer added this to the 1.1.0 milestone Jan 20, 2026
@dsyer dsyer merged commit 259717d into spring-projects:main Jan 21, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simplify gRPC Exception Handling

2 participants