Search in sources :

Example 1 with ErrorResponse

use of org.wso2.carbon.identity.rest.api.user.recovery.v1.model.ErrorResponse 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 ErrorResponse

use of org.wso2.carbon.identity.rest.api.user.recovery.v1.model.ErrorResponse 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 ErrorResponse

use of org.wso2.carbon.identity.rest.api.user.recovery.v1.model.ErrorResponse 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 ErrorResponse

use of org.wso2.carbon.identity.rest.api.user.recovery.v1.model.ErrorResponse 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 ErrorResponse

use of org.wso2.carbon.identity.rest.api.user.recovery.v1.model.ErrorResponse 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)53 APIError (org.wso2.carbon.identity.api.server.common.error.APIError)47 ErrorResponse (org.wso2.carbon.identity.api.server.common.error.ErrorResponse)47 Test (org.testng.annotations.Test)12 Response (feign.Response)11 APIError (org.wso2.carbon.identity.api.user.common.error.APIError)10 ErrorResponse (org.wso2.carbon.identity.api.user.common.error.ErrorResponse)9 ArrayList (java.util.ArrayList)6 DCRMServiceStub (org.wso2.carbon.apimgt.core.auth.DCRMServiceStub)6 OAuth2ServiceStubs (org.wso2.carbon.apimgt.core.auth.OAuth2ServiceStubs)6 ScopeRegistration (org.wso2.carbon.apimgt.core.auth.ScopeRegistration)6 OAuth2IntrospectionResponse (org.wso2.carbon.apimgt.core.auth.dto.OAuth2IntrospectionResponse)6 KeyManagementException (org.wso2.carbon.apimgt.core.exception.KeyManagementException)6 ErrorResponse (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.ErrorResponse)6 RetryErrorResponse (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.RetryErrorResponse)6 HashMap (java.util.HashMap)5 UserNameMapper (org.wso2.carbon.apimgt.core.api.UserNameMapper)5 SCIMServiceStub (org.wso2.carbon.apimgt.core.auth.SCIMServiceStub)5 IdentityProviderException (org.wso2.carbon.apimgt.core.exception.IdentityProviderException)5 ConnectionEstablishedResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.ConnectionEstablishedResponse)4