Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
emmdurin committed May 16, 2024
1 parent 1995564 commit 9258c85
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ CookieAffinityGatewayFilterFactory cookieAffinityGatewayFilterFactory() {
return new CookieAffinityGatewayFilterFactory();
}

@Bean
ServiceErrorGatewayFilterFactory serviceErrorGatewayFilterFactory() {
return new ServiceErrorGatewayFilterFactory();
}

@Bean
ProxyGatewayFilterFactory proxyGatewayFilterFactory() {
return new ProxyGatewayFilterFactory();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.georchestra.gateway.filter.headers;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.georchestra.gateway.filter.global.ResolveTargetGlobalFilter;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.core.Ordered;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseCookie;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import javax.validation.constraints.NotEmpty;

public class ServiceErrorGatewayFilterFactory extends AbstractGatewayFilterFactory<Object> {
public ServiceErrorGatewayFilterFactory() {
super(Object.class);
}

@Override
public GatewayFilter apply(final Object config) {
return new ServiceErrorGatewayFilter();
}

private static class ServiceErrorGatewayFilter implements GatewayFilter, Ordered {

public @Override Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
return chain.filter(exchange).then(Mono.fromRunnable(() -> {
if (exchange.getResponse().getStatusCode().is4xxClientError()) {
// log error ?
throw new RuntimeException("SERVICE ERROR");
}
}));
}

@Override
public int getOrder() {
return ResolveTargetGlobalFilter.ORDER + 1;
}
}
}

0 comments on commit 9258c85

Please sign in to comment.