Search in sources :

Example 1 with TenantManagementServerException

use of org.wso2.carbon.stratos.common.exception.TenantManagementServerException 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

Response (javax.ws.rs.core.Response)1 APIError (org.wso2.carbon.identity.api.server.common.error.APIError)1 ErrorResponse (org.wso2.carbon.identity.api.server.common.error.ErrorResponse)1 OwnerResponse (org.wso2.carbon.identity.api.server.tenant.management.v1.model.OwnerResponse)1 TenantsListResponse (org.wso2.carbon.identity.api.server.tenant.management.v1.model.TenantsListResponse)1 TenantManagementClientException (org.wso2.carbon.stratos.common.exception.TenantManagementClientException)1 TenantManagementServerException (org.wso2.carbon.stratos.common.exception.TenantManagementServerException)1