Search in sources :

Example 1 with RemoteFetchServerException

use of org.wso2.carbon.identity.remotefetch.common.exceptions.RemoteFetchServerException 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)

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 RemoteFetchConfigurationGetResponse (org.wso2.carbon.identity.api.server.fetch.remote.v1.model.RemoteFetchConfigurationGetResponse)1 RemoteFetchConfigurationListResponse (org.wso2.carbon.identity.api.server.fetch.remote.v1.model.RemoteFetchConfigurationListResponse)1 StatusListResponse (org.wso2.carbon.identity.api.server.fetch.remote.v1.model.StatusListResponse)1 RemoteFetchClientException (org.wso2.carbon.identity.remotefetch.common.exceptions.RemoteFetchClientException)1 RemoteFetchServerException (org.wso2.carbon.identity.remotefetch.common.exceptions.RemoteFetchServerException)1