Search in sources :

Example 26 with APIError

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

the class ServerConfigManagementService 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.CONFIG_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.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) 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 27 with APIError

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

the class ServerRemoteFetchConfigManagementService method handleRemoteFetchConfigurationException.

/**
 * This method is used to handle remote fetch core exception and create API error wit suitable response code and
 * status by checking its instance type.
 *
 * @param e         RemoteFetchCoreException.
 * @param errorEnum RemoteFetchConfigurationConstants.ErrorMessage
 * @param data      data
 * @return APIError
 */
private APIError handleRemoteFetchConfigurationException(RemoteFetchCoreException e, RemoteFetchConfigurationConstants.ErrorMessage errorEnum, String data) {
    ErrorResponse errorResponse;
    Response.Status status;
    if (e instanceof RemoteFetchClientException) {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorCode = errorCode.contains(RemoteFetchConfigurationConstants.ERROR_CODE_DELIMITER) ? errorCode : RemoteFetchConfigurationConstants.REMOTE_FETCH_CONFIGURATION_MANAGEMENT_PREFIX + errorCode;
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(e.getMessage());
        status = Response.Status.BAD_REQUEST;
    } else if (e instanceof RemoteFetchServerException) {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.getDescription());
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorCode = errorCode.contains(RemoteFetchConfigurationConstants.ERROR_CODE_DELIMITER) ? errorCode : RemoteFetchConfigurationConstants.REMOTE_FETCH_CONFIGURATION_MANAGEMENT_PREFIX + errorCode;
            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 : Response(javax.ws.rs.core.Response) StatusListResponse(org.wso2.carbon.identity.api.server.fetch.remote.v1.model.StatusListResponse) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) RemoteFetchConfigurationListResponse(org.wso2.carbon.identity.api.server.fetch.remote.v1.model.RemoteFetchConfigurationListResponse) RemoteFetchConfigurationGetResponse(org.wso2.carbon.identity.api.server.fetch.remote.v1.model.RemoteFetchConfigurationGetResponse) RemoteFetchServerException(org.wso2.carbon.identity.remotefetch.common.exceptions.RemoteFetchServerException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) RemoteFetchClientException(org.wso2.carbon.identity.remotefetch.common.exceptions.RemoteFetchClientException) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 28 with APIError

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

the class ServerApplicationMetadataService method handleException.

/**
 * If the passed exception has an error message, set it to the description of the API error response.
 *
 * @param e Exception caught.
 * @return APIError with exception error message if present.
 */
private APIError handleException(Exception e) {
    ErrorMessage errorEnum = ERROR_RETRIEVING_SAML_METADATA;
    String description = errorEnum.getDescription();
    if (StringUtils.isNotBlank(e.getMessage())) {
        description = e.getMessage();
    }
    return Utils.buildServerError(errorEnum.getCode(), errorEnum.getMessage(), description, e);
}
Also used : ErrorMessage(org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage)

Example 29 with APIError

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

the class Utils method buildNotFoundError.

public static APIError buildNotFoundError(String errorCode, String message, String description) {
    ErrorResponse errorResponse = new ErrorResponse.Builder().withCode(errorCode).withMessage(message).withDescription(description).build(log, description);
    Response.Status status = Response.Status.NOT_FOUND;
    return new APIError(status, errorResponse);
}
Also used : ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) Response(javax.ws.rs.core.Response) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 30 with APIError

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

the class Utils method buildClientError.

public static APIError buildClientError(String errorCode, String message, String description) {
    ErrorResponse errorResponse = new ErrorResponse.Builder().withCode(errorCode).withMessage(message).withDescription(description).build(log, description);
    Response.Status status = Response.Status.BAD_REQUEST;
    return new APIError(status, errorResponse);
}
Also used : ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) Response(javax.ws.rs.core.Response) 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