Search in sources :

Example 1 with APIError

use of org.wso2.carbon.identity.api.server.common.error.APIError 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 APIError

use of org.wso2.carbon.identity.api.server.common.error.APIError 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)

Example 3 with APIError

use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.

the class ServerTenantManagementService method handleNotImplementedCapabilities.

/**
 * Return Not Implemented error response for tenant List filtering which are not yet supported by the server.
 *
 * @param filter Filter string.
 */
private void handleNotImplementedCapabilities(String filter) {
    TenantManagementConstants.ErrorMessage errorEnum = null;
    if (filter != null) {
        errorEnum = TenantManagementConstants.ErrorMessage.ERROR_CODE_FILTER_NOT_IMPLEMENTED;
    }
    if (errorEnum != null) {
        ErrorResponse errorResponse = getErrorBuilder(errorEnum, null).build(log, errorEnum.getDescription());
        Response.Status status = Response.Status.NOT_IMPLEMENTED;
        throw new APIError(status, errorResponse);
    }
}
Also used : TenantsListResponse(org.wso2.carbon.identity.api.server.tenant.management.v1.model.TenantsListResponse) OwnerResponse(org.wso2.carbon.identity.api.server.tenant.management.v1.model.OwnerResponse) Response(javax.ws.rs.core.Response) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) TenantManagementConstants(org.wso2.carbon.identity.api.server.tenant.management.common.TenantManagementConstants) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 4 with APIError

use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.

the class ServerTenantManagementService method handleResourceLimitReached.

private APIError handleResourceLimitReached() {
    ErrorResponse errorResponse = getErrorBuilder(ERROR_CODE_TENANT_LIMIT_REACHED, null).build(log, ERROR_CODE_TENANT_LIMIT_REACHED.getDescription());
    Response.Status status = Response.Status.FORBIDDEN;
    return new APIError(status, errorResponse);
}
Also used : TenantsListResponse(org.wso2.carbon.identity.api.server.tenant.management.v1.model.TenantsListResponse) OwnerResponse(org.wso2.carbon.identity.api.server.tenant.management.v1.model.OwnerResponse) Response(javax.ws.rs.core.Response) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 5 with APIError

use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.

the class ServerTenantManagementService method handleTenantManagementException.

/**
 * Handle TenantMgtException, extract error code, error description and status code to be sent
 * in the response.
 *
 * @param e         TenantMgtException
 * @param errorEnum Error Message information.
 * @return APIError.
 */
private APIError handleTenantManagementException(TenantMgtException e, TenantManagementConstants.ErrorMessage errorEnum, String data) {
    ErrorResponse errorResponse;
    Response.Status status;
    if (e instanceof TenantManagementClientException) {
        if (ERROR_CODE_RESOURCE_LIMIT_REACHED.equals(e.getErrorCode())) {
            return handleResourceLimitReached();
        }
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(e.getMessage());
        status = Response.Status.BAD_REQUEST;
    } else if (e instanceof TenantManagementServerException) {
        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 : TenantsListResponse(org.wso2.carbon.identity.api.server.tenant.management.v1.model.TenantsListResponse) OwnerResponse(org.wso2.carbon.identity.api.server.tenant.management.v1.model.OwnerResponse) Response(javax.ws.rs.core.Response) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) TenantManagementClientException(org.wso2.carbon.stratos.common.exception.TenantManagementClientException) TenantManagementServerException(org.wso2.carbon.stratos.common.exception.TenantManagementServerException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Aggregations

APIError (org.wso2.carbon.identity.api.server.common.error.APIError)52 ErrorResponse (org.wso2.carbon.identity.api.server.common.error.ErrorResponse)47 Response (javax.ws.rs.core.Response)41 ConnectionEstablishedResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.ConnectionEstablishedResponse)4 UserStoreAttributeMappingResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreAttributeMappingResponse)4 UserStoreListResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreListResponse)4 UserStoreResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreResponse)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 URI (java.net.URI)3 ErrorMessage (org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage)3 FederatedAuthenticatorListResponse (org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticatorListResponse)3 IdentityProviderListResponse (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderListResponse)3 IdentityProviderResponse (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderResponse)3 IdentityProviderTemplateListResponse (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplateListResponse)3 OutboundConnectorListResponse (org.wso2.carbon.identity.api.server.idp.v1.model.OutboundConnectorListResponse)3 ProvisioningResponse (org.wso2.carbon.identity.api.server.idp.v1.model.ProvisioningResponse)3 OwnerResponse (org.wso2.carbon.identity.api.server.tenant.management.v1.model.OwnerResponse)3 TenantsListResponse (org.wso2.carbon.identity.api.server.tenant.management.v1.model.TenantsListResponse)3 IdentityApplicationManagementClientException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException)3 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig)3