use of me.proxer.library.api.ProxerException.ServerErrorType in project ProxerLibJava by proxer.
the class LoginTokenInterceptor method handleResponse.
private void handleResponse(final Response response) throws IOException {
final String responseBody = peekResponseBody(response);
final Matcher errorMatcher = ERROR_PATTERN.matcher(responseBody);
final HttpUrl url = response.request().url();
if (errorMatcher.find()) {
final int errorCode = Integer.parseInt(errorMatcher.group(1));
final ServerErrorType errorType = ServerErrorType.fromErrorCodeOrNull(errorCode);
if (errorType != null && isLoginError(errorType)) {
loginTokenManager.persist(null);
}
} else if (url.pathSegments().equals(LOGIN_PATH)) {
final Matcher loginTokenMatcher = LOGIN_TOKEN_PATTERN.matcher(responseBody);
if (loginTokenMatcher.find()) {
loginTokenManager.persist(loginTokenMatcher.group(1).trim());
} else {
throw new JsonDataException("No token found after successful login.");
}
} else if (url.pathSegments().equals(LOGOUT_PATH)) {
loginTokenManager.persist(null);
}
}
Aggregations