diff options
author | 2018-11-01 13:29:29 +0300 | |
---|---|---|
committer | 2018-11-01 13:29:29 +0300 | |
commit | 2b9d2478833a060df76c855e78c46e33c032db49 (patch) | |
tree | a516cb597704529cf1de623eb807d219a5510d49 /juick-server/src/main/java/com/juick/server/configuration/ActivityPubClientErrorHandler.java | |
parent | 0dc2727e0633a4b865d814c7ab8450e3c815e511 (diff) |
ActivityPub: fix 410 error handler
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/configuration/ActivityPubClientErrorHandler.java')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/configuration/ActivityPubClientErrorHandler.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/juick-server/src/main/java/com/juick/server/configuration/ActivityPubClientErrorHandler.java b/juick-server/src/main/java/com/juick/server/configuration/ActivityPubClientErrorHandler.java new file mode 100644 index 00000000..ad8e9b2f --- /dev/null +++ b/juick-server/src/main/java/com/juick/server/configuration/ActivityPubClientErrorHandler.java @@ -0,0 +1,35 @@ +package com.juick.server.configuration; + +import com.juick.service.activities.DeleteUserEvent; +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.client.ClientHttpResponse; +import org.springframework.stereotype.Component; +import org.springframework.web.client.DefaultResponseErrorHandler; + +import javax.annotation.Nonnull; +import javax.inject.Inject; +import java.io.IOException; +import java.net.URI; +import java.nio.charset.StandardCharsets; + +@Component +public class ActivityPubClientErrorHandler extends DefaultResponseErrorHandler { + private static final Logger logger = LoggerFactory.getLogger(ActivityPubClientErrorHandler.class); + + @Inject + private ApplicationEventPublisher applicationEventPublisher; + @Override + public void handleError(URI contextUri, HttpMethod method, @Nonnull ClientHttpResponse response) throws IOException { + logger.warn("HTTP ERROR {} {} : {}", response.getStatusCode().value(), + response.getStatusText(), IOUtils.toString(response.getBody(), StandardCharsets.UTF_8)); + if (response.getStatusCode().equals(HttpStatus.GONE)) { + logger.warn("Server report {} is gone, deleting", response); + applicationEventPublisher.publishEvent(new DeleteUserEvent(this, contextUri.toASCIIString())); + } + } +} |