-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...rc/main/java/org/georchestra/gateway/filter/headers/ServiceErrorGatewayFilterFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |