All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bybutter.sisyphus.starter.grpc.transcoding.TranscodingNotSupportExceptionMapper.kt Maven / Gradle / Ivy

Go to download

Starter for building gRPC server which with HTTP and gRPC Transcoding in Sisyphus Framework

There is a newer version: 2.1.22
Show newest version
package com.bybutter.sisyphus.starter.grpc.transcoding

import org.springframework.core.annotation.Order
import org.springframework.http.HttpStatus
import org.springframework.stereotype.Component
import org.springframework.web.server.ResponseStatusException
import org.springframework.web.server.ServerWebExchange
import org.springframework.web.server.WebExceptionHandler
import reactor.core.publisher.Mono

@Component
@Order(-1)
class TranscodingNotSupportExceptionMapper : WebExceptionHandler {
    override fun handle(exchange: ServerWebExchange, ex: Throwable): Mono {
        // org.springframework.web.reactive.DispatcherHandler will throw ResponseStatusException with reason 'No matching handler'
        // org.springframework.web.reactive.resource.ResourceWebHandler will throw ResponseStatusException with no reason
        // We map those ResponseStatusException to TranscodingNotSupportException
        if (ex is ResponseStatusException && ex.status == HttpStatus.NOT_FOUND &&
            (ex.reason == null || ex.reason == "No matching handler")
        ) {
            return Mono.error(TranscodingNotSupportException())
        }
        return Mono.error(ex)
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy