use of org.hyperledger.fabric_ca.sdk.exception.HTTPException in project fabric-sdk-java by hyperledger.
the class HFCAIdentity method update.
/**
* update an identity
*
* @param registrar The identity of the registrar (i.e. who is performing the registration).
* @return statusCode The HTTP status code in the response
* @throws IdentityException if adding an identity fails.
* @throws InvalidArgumentException Invalid (null) argument specified
*/
public int update(User registrar) throws IdentityException, InvalidArgumentException {
if (this.deleted) {
throw new IdentityException("Identity has been deleted");
}
if (registrar == null) {
throw new InvalidArgumentException("Registrar should be a valid member");
}
String updateURL = "";
try {
updateURL = client.getURL(HFCA_IDENTITY + "/" + getEnrollmentId());
logger.debug(format("identity url: %s, registrar: %s", updateURL, registrar.getName()));
String body = client.toJson(idToJsonObject());
JsonObject result = client.httpPut(updateURL, body, registrar);
statusCode = result.getInt("statusCode");
if (statusCode < 400) {
getHFCAIdentity(result);
logger.debug(format("identity url: %s, registrar: %s done.", updateURL, registrar));
}
return statusCode;
} catch (HTTPException e) {
String msg = format("[Code: %d] - Error while updating user '%s' from url '%s': %s", e.getStatusCode(), getEnrollmentId(), updateURL, e.getMessage());
IdentityException identityException = new IdentityException(msg, e);
logger.error(msg);
throw identityException;
} catch (Exception e) {
String msg = format("Error while updating user '%s' from url '%s': %s", getEnrollmentId(), updateURL, e.getMessage());
IdentityException identityException = new IdentityException(msg, e);
logger.error(msg);
throw identityException;
}
}
Aggregations