final LoginError error = objectMapper.readValue(responseContent, LoginError.class);
final String msg = String.format("Login error code:[%s] description:[%s]",
error.getError(), error.getErrorDescription());
final List<RestError> errors = new ArrayList<RestError>();
errors.add(new RestError(msg, error.getErrorDescription()));
throw new SalesforceException(errors, HttpStatus.BAD_REQUEST_400);
default:
throw new SalesforceException(String.format("Login error status:[%s] reason:[%s]",
responseStatus, loginPost.getReason()), responseStatus);
}
break;
case HttpExchange.STATUS_EXCEPTED:
final Throwable ex = loginPost.getException();
throw new SalesforceException(
String.format("Unexpected login exception: %s", ex.getMessage()), ex);
case HttpExchange.STATUS_CANCELLED:
throw new SalesforceException("Login request CANCELLED!", null);
case HttpExchange.STATUS_EXPIRED:
throw new SalesforceException("Login request TIMEOUT!", null);
default:
throw new SalesforceException("Unknow status: " + exchangeState, null);
}
} catch (IOException e) {
String msg = "Login error: unexpected exception " + e.getMessage();
throw new SalesforceException(msg, e);
} catch (InterruptedException e) {
String msg = "Login error: unexpected exception " + e.getMessage();
throw new SalesforceException(msg, e);
}
}
return accessToken;
}