Search in sources :

Example 1 with SecretManagementClientException

use of org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementClientException in project identity-api-server by wso2.

the class SecretManagementService method handleSecretMgtException.

private APIError handleSecretMgtException(SecretManagementException e, SecretManagementConstants.ErrorMessage errorEnum, String data) {
    ErrorResponse errorResponse;
    Response.Status status;
    if (e instanceof SecretManagementClientException) {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(e.getMessage());
        if (ERROR_CODE_SECRET_ALREADY_EXISTS.getCode().equals(e.getErrorCode())) {
            status = Response.Status.CONFLICT;
        } else if (ERROR_CODE_SECRET_DOES_NOT_EXISTS.getCode().equals(e.getErrorCode())) {
            status = Response.Status.NOT_FOUND;
        } else {
            status = Response.Status.BAD_REQUEST;
        }
    } else if (e instanceof SecretManagementServerException) {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.getDescription());
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(e.getMessage());
        status = Response.Status.INTERNAL_SERVER_ERROR;
    } else {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.getDescription());
        status = Response.Status.INTERNAL_SERVER_ERROR;
    }
    return new APIError(status, errorResponse);
}
Also used : ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) SecretResponse(org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretResponse) Response(javax.ws.rs.core.Response) SecretManagementClientException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementClientException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) SecretManagementServerException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementServerException)

Example 2 with SecretManagementClientException

use of org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementClientException in project identity-api-server by wso2.

the class SecretTypeManagementService method handleSecretMgtException.

private APIError handleSecretMgtException(SecretManagementException e, SecretManagementConstants.ErrorMessage errorEnum, String data) {
    ErrorResponse errorResponse;
    Response.Status status;
    if (e instanceof SecretManagementClientException) {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(e.getMessage());
        if (ERROR_CODE_SECRET_TYPE_ALREADY_EXISTS.getCode().equals(e.getErrorCode())) {
            status = Response.Status.CONFLICT;
        } else if (ERROR_CODE_SECRET_TYPE_DOES_NOT_EXISTS.getCode().equals(e.getErrorCode())) {
            status = Response.Status.NOT_FOUND;
        } else {
            status = Response.Status.BAD_REQUEST;
        }
    } else if (e instanceof SecretManagementServerException) {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.getDescription());
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(e.getMessage());
        status = Response.Status.INTERNAL_SERVER_ERROR;
    } else {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.getDescription());
        status = Response.Status.INTERNAL_SERVER_ERROR;
    }
    return new APIError(status, errorResponse);
}
Also used : ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) SecretTypeResponse(org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretTypeResponse) Response(javax.ws.rs.core.Response) SecretManagementClientException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementClientException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) SecretManagementServerException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementServerException)

Aggregations

Response (javax.ws.rs.core.Response)2 APIError (org.wso2.carbon.identity.api.server.common.error.APIError)2 ErrorResponse (org.wso2.carbon.identity.api.server.common.error.ErrorResponse)2 SecretManagementClientException (org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementClientException)2 SecretManagementServerException (org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementServerException)2 SecretResponse (org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretResponse)1 SecretTypeResponse (org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretTypeResponse)1