Search in sources :

Example 41 with APIError

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

the class ServerConfigManagementService method handleIdPException.

/**
 * Handle IdentityProviderManagementException, extract error code, error description and status code to be sent
 * in the response.
 *
 * @param e         IdentityProviderManagementException.
 * @param errorEnum Error Message information.
 * @return APIError.
 */
private APIError handleIdPException(IdentityProviderManagementException e, Constants.ErrorMessage errorEnum, String data) {
    ErrorResponse errorResponse;
    Response.Status status;
    if (e instanceof IdentityProviderManagementClientException) {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorCode = errorCode.contains(org.wso2.carbon.identity.api.server.common.Constants.ERROR_CODE_DELIMITER) ? errorCode : Constants.CONFIG_ERROR_PREFIX + errorCode;
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(e.getMessage());
        status = Response.Status.BAD_REQUEST;
    } else if (e instanceof IdentityProviderManagementServerException) {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.description());
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorCode = errorCode.contains(org.wso2.carbon.identity.api.server.common.Constants.ERROR_CODE_DELIMITER) ? errorCode : Constants.CONFIG_ERROR_PREFIX + errorCode;
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(e.getMessage());
        status = Response.Status.INTERNAL_SERVER_ERROR;
    } else {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.description());
        status = Response.Status.INTERNAL_SERVER_ERROR;
    }
    return new APIError(status, errorResponse);
}
Also used : Response(javax.ws.rs.core.Response) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) IdentityProviderManagementServerException(org.wso2.carbon.idp.mgt.IdentityProviderManagementServerException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) IdentityProviderManagementClientException(org.wso2.carbon.idp.mgt.IdentityProviderManagementClientException) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 42 with APIError

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

the class ServerEmailTemplatesService method handleI18nEmailMgtException.

/**
 * Handle I18nEmailMgtException, i.e. extract error description from the exception and set to the
 * API Error Response, along with an status code to be sent in the response.
 *
 * @param exception Exception thrown
 * @param errorEnum Corresponding error enum
 * @return API Error object.
 */
private APIError handleI18nEmailMgtException(I18nEmailMgtException exception, Constants.ErrorMessage errorEnum) {
    ErrorResponse errorResponse;
    Response.Status status;
    if (exception instanceof I18nEmailMgtInternalException && Constants.getMappedErrorMessage(exception.getErrorCode()) != null) {
        // Specific error with code is found.
        Constants.ErrorMessage errorMessage = Constants.getMappedErrorMessage(exception.getErrorCode());
        errorResponse = getErrorBuilder(errorMessage).build(log, exception, errorEnum.getDescription());
        status = errorMessage.getHttpStatus();
    } else if (exception instanceof I18nEmailMgtClientException) {
        // Send client error with original exception message.
        errorResponse = getErrorBuilder(errorEnum).build(log, exception.getMessage());
        errorResponse.setDescription(exception.getMessage());
        status = Response.Status.BAD_REQUEST;
    } else {
        // Server error
        errorResponse = getErrorBuilder(errorEnum).build(log, exception, 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) Response(javax.ws.rs.core.Response) I18nEmailMgtClientException(org.wso2.carbon.email.mgt.exceptions.I18nEmailMgtClientException) I18nEmailMgtInternalException(org.wso2.carbon.email.mgt.exceptions.I18nEmailMgtInternalException) I18nMgtConstants(org.wso2.carbon.email.mgt.constants.I18nMgtConstants) Constants(org.wso2.carbon.identity.api.server.email.template.common.Constants) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 43 with APIError

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

the class ServerIdentityGovernanceService method handleNotImplementedCapabilities.

private void handleNotImplementedCapabilities(Integer limit, Integer offset, String filter, String sort) {
    GovernanceConstants.ErrorMessage errorEnum = null;
    if (limit != null) {
        errorEnum = ERROR_CODE_PAGINATION_NOT_IMPLEMENTED;
    } else if (offset != null) {
        errorEnum = ERROR_CODE_PAGINATION_NOT_IMPLEMENTED;
    } else if (filter != null) {
        errorEnum = ERROR_CODE_FILTERING_NOT_IMPLEMENTED;
    } else if (sort != null) {
        errorEnum = ERROR_CODE_SORTING_NOT_IMPLEMENTED;
    }
    if (errorEnum != null) {
        ErrorResponse errorResponse = getErrorBuilder(errorEnum).build(LOG, errorEnum.getDescription());
        Response.Status status = Response.Status.NOT_IMPLEMENTED;
        throw new APIError(status, errorResponse);
    }
}
Also used : ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) Response(javax.ws.rs.core.Response) GovernanceConstants(org.wso2.carbon.identity.api.server.identity.governance.common.GovernanceConstants) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 44 with APIError

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

the class CORSService method handleCORSException.

private APIError handleCORSException(CORSManagementServiceException e, Constants.ErrorMessage errorEnum, String data) {
    ErrorResponse errorResponse;
    Response.Status status;
    if (e instanceof CORSManagementServiceClientException) {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorCode = errorCode.contains(org.wso2.carbon.identity.api.server.common.Constants.ERROR_CODE_DELIMITER) ? errorCode : Constants.CORS_ERROR_PREFIX + errorCode;
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(e.getMessage());
        status = Response.Status.BAD_REQUEST;
    } else if (e instanceof CORSManagementServiceServerException) {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.description());
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorCode = errorCode.contains(org.wso2.carbon.identity.api.server.common.Constants.ERROR_CODE_DELIMITER) ? errorCode : Constants.CORS_ERROR_PREFIX + errorCode;
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(e.getMessage());
        status = Response.Status.INTERNAL_SERVER_ERROR;
    } else {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.description());
        status = Response.Status.INTERNAL_SERVER_ERROR;
    }
    return new APIError(status, errorResponse);
}
Also used : ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) Response(javax.ws.rs.core.Response) CORSManagementServiceClientException(org.wso2.carbon.identity.cors.mgt.core.exception.CORSManagementServiceClientException) CORSManagementServiceServerException(org.wso2.carbon.identity.cors.mgt.core.exception.CORSManagementServiceServerException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 45 with APIError

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

the class ServerIdpManagementService method handleResourceLimitReached.

private APIError handleResourceLimitReached() {
    ErrorResponse errorResponse = getErrorBuilder(ERROR_CODE_IDP_LIMIT_REACHED, null).build(log, ERROR_CODE_IDP_LIMIT_REACHED.getDescription());
    Response.Status status = Response.Status.FORBIDDEN;
    return new APIError(status, errorResponse);
}
Also used : IdentityProviderTemplateListResponse(org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplateListResponse) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) IdentityProviderListResponse(org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderListResponse) FederatedAuthenticatorListResponse(org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticatorListResponse) Response(javax.ws.rs.core.Response) IdentityProviderResponse(org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderResponse) OutboundConnectorListResponse(org.wso2.carbon.identity.api.server.idp.v1.model.OutboundConnectorListResponse) ProvisioningResponse(org.wso2.carbon.identity.api.server.idp.v1.model.ProvisioningResponse) 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