package com.firefly.example.reactive.coffee.store.router.impl.sys;

import com.firefly.annotation.Component;
import com.firefly.codec.http2.model.HttpStatus;
import com.firefly.example.reactive.coffee.store.vo.Response;
import com.firefly.server.http2.router.Handler;
import com.firefly.server.http2.router.RoutingContext;
import com.firefly.utils.log.slf4j.ext.LazyLogger;
import reactor.core.publisher.Mono;

/**
 * @author Pengtao Qiu
 */
@Component("globalHandler")
public class GlobalHandler implements Handler {

    private static final LazyLogger logger = LazyLogger.create();

    @Override
    public void handle(RoutingContext ctx) {
        ctx.getResponse().setAsynchronous(true);
        Mono.fromFuture(ctx.nextFuture()).subscribe(ret -> ctx.end(), ex -> {
            ctx.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500);
            logger.error(() -> "server exception", ex);
            Response<Boolean> response = new Response<>();
            response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500);
            response.setMessage("server exception, " + ex.getMessage());
            ctx.writeJson(response).end();
        });
    }
}

@@ -404,16 +404,44 @@
 .Mono;%0A%0A
+import java.time.Duration;%0A%0A
 /**%0A * @
@@ -756,16 +756,73 @@
 uture())
+%0A            .timeout(Duration.ofSeconds(1))%0A            
 .subscri
@@ -850,16 +850,20 @@
 ex -%3E %7B%0A
+    
         
@@ -931,16 +931,20 @@
         
+   
+ 
 logger.e
@@ -979,16 +979,20 @@
 %22, ex);%0A
+    
         
@@ -1046,32 +1046,36 @@
 ();%0A            
+ 
+   
 response.setStat
@@ -1120,32 +1120,36 @@
 0);%0A            
+  
+  
 response.setMess
@@ -1201,24 +1201,28 @@
             
+    
 ctx.writeJso
@@ -1236,24 +1236,28 @@
 nse).end();%0A
+    
         %7D);%0A

clean up codes