aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2021-08-27 17:14:34 +0300
committerGravatar Vitaly Takmazov2021-08-27 17:19:22 +0300
commitc088659386565a3590ab58eb10b21b5c8547fe6c (patch)
tree0295a505015045b961943f3d53f9c2667924fa21 /src/main
parente0f560c662d20b1956cb706b6423596efd33e8fb (diff)
handle WebFinger errors
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/juick/SignatureManager.java22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/main/java/com/juick/SignatureManager.java b/src/main/java/com/juick/SignatureManager.java
index bccc46be..13c3fff2 100644
--- a/src/main/java/com/juick/SignatureManager.java
+++ b/src/main/java/com/juick/SignatureManager.java
@@ -35,6 +35,7 @@ import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import org.tomitribe.auth.signatures.Base64;
@@ -178,17 +179,22 @@ public class SignatureManager {
HttpHeaders headers = new HttpHeaders();
headers.add("Accept", "application/jrd+json");
HttpEntity<Void> webfingerRequest = new HttpEntity<>(headers);
- ResponseEntity<Account> response = apClient.exchange(resourceUri, HttpMethod.GET, webfingerRequest,
- Account.class);
- if (response.getStatusCode().is2xxSuccessful()) {
- Account acctData = response.getBody();
- if (acctData != null) {
- for (Link l : acctData.getLinks()) {
- if (l.getRel().equals("self") && l.getType().equals(ACTIVITY_MEDIA_TYPE)) {
- return getContext(URI.create(l.getHref()));
+ try {
+ ResponseEntity<Account> response = apClient.exchange(resourceUri, HttpMethod.GET, webfingerRequest,
+ Account.class);
+ if (response.getStatusCode().is2xxSuccessful()) {
+ Account acctData = response.getBody();
+ if (acctData != null) {
+ for (Link l : acctData.getLinks()) {
+ if (l.getRel().equals("self") && l.getType().equals(ACTIVITY_MEDIA_TYPE)) {
+ return getContext(URI.create(l.getHref()));
+ }
}
}
}
+ } catch (RestClientException e) {
+ logger.warn("Cannot discover person {}: {}", acct, e.getMessage());
+ return Optional.empty();
}
return Optional.empty();
}