void HttpUtil::ErrorCodeToHttpStatus()

in src/prod/src/Management/HttpTransport/HttpUtil.cpp [206:461]


void HttpUtil::ErrorCodeToHttpStatus(
    __in ErrorCode error,
    __out USHORT &httpStatus,
    __out wstring &httpStatusLine)
{
    switch (error.ToHResult())
    {
    case STATUS_SUCCESS:
    {
        httpStatus = HttpStatusCode::Ok;
        httpStatusLine = L"OK";
        break;
    }

    case E_INVALIDARG:
    {
        httpStatus = HttpStatusCode::BadRequest;
        httpStatusLine = L"Bad Request";
        break;
    }

    case E_ACCESSDENIED:
    {
        httpStatus = HttpStatusCode::Forbidden;
        httpStatusLine = L"Access Denied";
        break;
    }

    case E_NOTIMPL:
    {
        httpStatus = HttpStatusCode::NotImplemented;
        httpStatusLine = L"Not Implemented";
        break;
    }

    case (int)FABRIC_E_APPLICATION_TYPE_ALREADY_EXISTS:
    case (int)FABRIC_E_APPLICATION_ALREADY_EXISTS:
    case (int)FABRIC_E_APPLICATION_ALREADY_IN_TARGET_VERSION:
    case (int)FABRIC_E_APPLICATION_TYPE_PROVISION_IN_PROGRESS:
    case (int)FABRIC_E_APPLICATION_UPGRADE_IN_PROGRESS:
    case (int)FABRIC_E_SERVICE_ALREADY_EXISTS:
    case (int)FABRIC_E_SERVICE_GROUP_ALREADY_EXISTS:
    case (int)FABRIC_E_APPLICATION_TYPE_IN_USE:
    case (int)FABRIC_E_FABRIC_ALREADY_IN_TARGET_VERSION:
    case (int)FABRIC_E_FABRIC_VERSION_ALREADY_EXISTS:
    case (int)FABRIC_E_FABRIC_VERSION_IN_USE:
    case (int)FABRIC_E_FABRIC_UPGRADE_IN_PROGRESS:
    case (int)FABRIC_E_NAME_ALREADY_EXISTS:
    case (int)FABRIC_E_NAME_NOT_EMPTY:
    case (int)FABRIC_E_PROPERTY_CHECK_FAILED:
    case (int)FABRIC_E_SERVICE_METADATA_MISMATCH:
    case (int)FABRIC_E_SERVICE_TYPE_MISMATCH:
    case (int)FABRIC_E_WRITE_CONFLICT:
    case (int)FABRIC_E_HEALTH_STALE_REPORT:
    case (int)FABRIC_E_SEQUENCE_NUMBER_CHECK_FAILED:
    case (int)FABRIC_E_INSTANCE_ID_MISMATCH:
    case (int)FABRIC_E_NODE_HAS_NOT_STOPPED_YET:
    case (int)FABRIC_E_REPAIR_TASK_ALREADY_EXISTS:
    case (int)FABRIC_E_SERVICE_TYPE_ALREADY_REGISTERED:
    case (int)FABRIC_E_APPLICATION_UPDATE_IN_PROGRESS:
    case (int)FABRIC_E_HEALTH_MAX_REPORTS_REACHED:
    case (int)FABRIC_E_DUPLICATE_SERVICE_NOTIFICATION_FILTER_NAME:
    case (int)FABRIC_E_PRIMARY_ALREADY_EXISTS:
    case (int)FABRIC_E_SECONDARY_ALREADY_EXISTS:
    case (int)FABRIC_E_TEST_COMMAND_OPERATION_ID_ALREADY_EXISTS:
    case (int)FABRIC_E_UPLOAD_SESSION_ID_CONFLICT:
    case (int)FABRIC_E_COMPOSE_DEPLOYMENT_ALREADY_EXISTS:
    case (int)FABRIC_E_RESTORE_SOURCE_TARGET_PARTITION_MISMATCH:
    case (int)FABRIC_E_BACKUP_POLICY_ALREADY_EXISTS:
    case (int)FABRIC_E_NETWORK_IN_USE:
    {
        httpStatus = HttpStatusCode::Conflict;
        httpStatusLine = error.ErrorCodeValueToString();
        break;
    }

    case (int)FABRIC_E_INVALID_PARTITION_KEY:
    case (int)FABRIC_E_IMAGEBUILDER_VALIDATION_ERROR:
    case (int)FABRIC_E_IMAGEBUILDER_RESERVED_DIRECTORY_ERROR:
    case (int)FABRIC_E_INVALID_ADDRESS:
    case (int)FABRIC_E_APPLICATION_NOT_UPGRADING:
    case (int)FABRIC_E_APPLICATION_UPGRADE_VALIDATION_ERROR:
    case (int)FABRIC_E_FABRIC_NOT_UPGRADING:
    case (int)FABRIC_E_FABRIC_UPGRADE_VALIDATION_ERROR:
    case (int)FABRIC_E_INVALID_ALLOWED_COMMON_NAME_LIST:
    case (int)FABRIC_E_INVALID_CONFIGURATION:
    case (int)FABRIC_E_INVALID_CREDENTIAL_TYPE:
    case (int)FABRIC_E_INVALID_CREDENTIALS:
    case (int)FABRIC_E_INVALID_NAME_URI:
    case (int)FABRIC_E_INVALID_PROTECTION_LEVEL:
    case (int)FABRIC_E_INVALID_SUBJECT_NAME:
    case (int)FABRIC_E_INVALID_X509_FIND_TYPE:
    case (int)FABRIC_E_INVALID_X509_STORE:
    case (int)FABRIC_E_INVALID_X509_STORE_LOCATION:
    case (int)FABRIC_E_INVALID_X509_STORE_NAME:
    case (int)FABRIC_E_INVALID_X509_THUMBPRINT:
    case (int)FABRIC_E_PATH_TOO_LONG:
    case (int)FABRIC_E_KEY_TOO_LARGE:
    case (int)FABRIC_E_SERVICE_AFFINITY_CHAIN_NOT_SUPPORTED:
    case (int)FABRIC_E_INVALID_ATOMIC_GROUP:
    case (int)FABRIC_E_VALUE_EMPTY:
    case (int)FABRIC_E_REPAIR_TASK_NOT_FOUND:
    case (int)FABRIC_E_USER_ROLE_CLIENT_CERTIFICATE_NOT_CONFIGURED:
    case (int)FABRIC_E_SERVICE_TYPE_NOT_REGISTERED:
    case (int)FABRIC_E_INVALID_OPERATION:
    case (int)FABRIC_E_TRANSACTION_NOT_ACTIVE:
    case (int)FABRIC_E_TRANSACTION_TOO_LARGE:
    case (int)FABRIC_E_CONFIGURATION_SECTION_NOT_FOUND:
    case (int)FABRIC_E_INVALID_DIRECTORY:
    case (int)FABRIC_E_UPGRADE_DOMAIN_ALREADY_COMPLETED:
    case (int)FABRIC_E_INVALID_X509_NAME_LIST:
    case (int)FABRIC_E_INVALID_SERVICE_TYPE:
    case (int)FABRIC_E_REPLICATION_OPERATION_TOO_LARGE:
    case (int)FABRIC_E_INSUFFICIENT_CLUSTER_CAPACITY:
    case (int)FABRIC_E_CONSTRAINT_KEY_UNDEFINED:
    case (int)FABRIC_E_CONSTRAINT_NOT_SATISFIED:
    case (int)FABRIC_E_INVALID_PACKAGE_SHARING_POLICY:
    case (int)FABRIC_E_PREDEPLOYMENT_NOT_ALLOWED:
    case (int)FABRIC_E_MULTITHREADED_TRANSACTIONS_NOT_ALLOWED:
    case (int)FABRIC_E_CERTIFICATE_NOT_FOUND:
    case (int)FABRIC_E_INVALID_BACKUP_SETTING:
    case (int)FABRIC_E_INVALID_RESTORE_DATA:
    case (int)FABRIC_E_RESTORE_SAFE_CHECK_FAILED:
    case (int)FABRIC_E_DUPLICATE_BACKUPS:
    case (int)FABRIC_E_INVALID_BACKUP_CHAIN:
    case (int)FABRIC_E_INVALID_BACKUP:
    case (int)FABRIC_E_MISSING_FULL_BACKUP:
    case (int)FABRIC_E_INVALID_REPLICA_OPERATION:
    case (int)FABRIC_E_INVALID_REPLICA_STATE:
    case (int)FABRIC_E_BACKUP_IN_PROGRESS:
    case (int)FABRIC_E_INVALID_PARTITION_OPERATION:
    case (int)FABRIC_E_INVALID_TEST_COMMAND_STATE:
    case (int)FABRIC_E_INVALID_PARTITION_SELECTOR:
    case (int)FABRIC_E_INVALID_REPLICA_SELECTOR:
    case (int)FABRIC_E_CHAOS_ALREADY_RUNNING:
    case (int)FABRIC_E_STOP_IN_PROGRESS:
    case (int)FABRIC_E_ALREADY_STOPPED:
    case (int)FABRIC_E_NODE_IS_UP:
    case (int)FABRIC_E_NODE_IS_DOWN:
    case (int)FABRIC_E_NODE_TRANSITION_IN_PROGRESS:
    case (int)FABRIC_E_INVALID_INSTANCE_ID:
    case (int)FABRIC_E_INVALID_DURATION:
    case (int)FABRIC_E_UPLOAD_SESSION_RANGE_NOT_SATISFIABLE:
    case (int)FABRIC_E_INVALID_DNS_NAME:
    case (int)FABRIC_E_INVALID_FOR_STATEFUL_SERVICES:
    case (int)FABRIC_E_INVALID_FOR_STATELESS_SERVICES:
    case (int)FABRIC_E_ONLY_VALID_FOR_STATEFUL_PERSISTENT_SERVICES:
    case (int)FABRIC_E_INVALID_UPLOAD_SESSION_ID:
    case (int)FABRIC_E_BACKUP_NOT_ENABLED:
    case (int)FABRIC_E_BACKUP_POLICY_DOES_NOT_EXIST:
    case (int)FABRIC_E_FAULT_ANALYSIS_SERVICE_NOT_ENABLED:
    case (int)FABRIC_E_INVALID_SERVICE_SCALING_POLICY:
    case (int)FABRIC_E_COMPOSE_DEPLOYMENT_NOT_UPGRADING:
    case (int)FABRIC_E_VOLUME_NOT_FOUND:
    case (int)FABRIC_E_NETWORK_NOT_FOUND:
    case (int)FABRIC_E_ENDPOINT_NOT_REFERENCED:
    {
        httpStatus = HttpStatusCode::BadRequest;
        httpStatusLine = error.ErrorCodeValueToString();
        break;
    }

    case (int)FABRIC_E_MESSAGE_TOO_LARGE:
    case (int)FABRIC_E_VALUE_TOO_LARGE:
    {
        httpStatus = HttpStatusCode::RequestEntityTooLarge;
        httpStatusLine = error.ErrorCodeValueToString();
        break;
    }

    case (int)FABRIC_E_NODE_NOT_FOUND:
    case (int)FABRIC_E_APPLICATION_TYPE_NOT_FOUND:
    case (int)FABRIC_E_APPLICATION_NOT_FOUND:
    case (int)FABRIC_E_SERVICE_TYPE_NOT_FOUND:
    case (int)FABRIC_E_SERVICE_DOES_NOT_EXIST:
    case (int)FABRIC_E_SERVICE_TYPE_TEMPLATE_NOT_FOUND:
    case (int)FABRIC_E_PARTITION_NOT_FOUND:
    case (int)FABRIC_E_REPLICA_DOES_NOT_EXIST:
    case (int)FABRIC_E_SERVICE_GROUP_DOES_NOT_EXIST:
    case (int)FABRIC_E_ENDPOINT_NOT_FOUND:
    case (int)FABRIC_E_CODE_PACKAGE_NOT_FOUND:
    case (int)FABRIC_E_CONFIGURATION_PACKAGE_NOT_FOUND:
    case (int)FABRIC_E_CONFIGURATION_PARAMETER_NOT_FOUND:
    case (int)FABRIC_E_DATA_PACKAGE_NOT_FOUND:
    case (int)FABRIC_E_DIRECTORY_NOT_FOUND:
    case (int)FABRIC_E_FABRIC_VERSION_NOT_FOUND:
    case (int)FABRIC_E_FILE_NOT_FOUND:
    case (int)FABRIC_E_NAME_DOES_NOT_EXIST:
    case (int)FABRIC_E_PROPERTY_DOES_NOT_EXIST:
    case (int)FABRIC_E_ENUMERATION_COMPLETED:
    case (int)FABRIC_E_SERVICE_MANIFEST_NOT_FOUND:
    case (int)FABRIC_E_KEY_NOT_FOUND:
    case (int)FABRIC_E_HEALTH_ENTITY_NOT_FOUND:
    case (int)FABRIC_E_SERVICE_ENDPOINT_RESOURCE_NOT_FOUND:
    case (int)FABRIC_E_DNS_SERVICE_NOT_FOUND:
    case (int)FABRIC_E_COMPOSE_DEPLOYMENT_NOT_FOUND:
    {
        httpStatus = HttpStatusCode::NotFound;
        httpStatusLine = error.ErrorCodeValueToString();
        break;
    }

    case (int)FABRIC_E_COMMUNICATION_ERROR:
    case (int)FABRIC_E_OPERATION_NOT_COMPLETE:
    case (int)FABRIC_E_TIMEOUT:
    {
        httpStatus = HttpStatusCode::GatewayTimeout;
        httpStatusLine = error.ErrorCodeValueToString();
        break;
    }

    case (int)FABRIC_E_NO_WRITE_QUORUM:
    case (int)FABRIC_E_NOT_PRIMARY:
    case (int)FABRIC_E_NOT_READY:
    case (int)FABRIC_E_OBJECT_CLOSED:
    case (int)FABRIC_E_SERVICE_OFFLINE:
    case E_ABORT:
    case (int)FABRIC_E_CONNECTION_CLOSED_BY_REMOTE_END:
    case (int)FABRIC_E_RECONFIGURATION_PENDING:
    case (int)FABRIC_E_REPLICATION_QUEUE_FULL:
    case (int)FABRIC_E_SERVICE_TOO_BUSY:
    {
        httpStatus = HttpStatusCode::ServiceUnavailable;
        httpStatusLine = error.ErrorCodeValueToString();
        break;
    }

    case (int)FABRIC_E_GATEWAY_NOT_REACHABLE:
    {
        httpStatus = HttpStatusCode::BadGateway;
        httpStatusLine = error.ErrorCodeValueToString();
        break;
    }

    case (int)FABRIC_E_SERVER_AUTHENTICATION_FAILED:
    {
        httpStatus = HttpStatusCode::Unauthorized;
        httpStatusLine = error.ErrorCodeValueToString();
        break;
    }

    case ErrorCodeValue::NotFound:
    {
        httpStatus = HttpStatusCode::NotFound;
        httpStatusLine = error.ErrorCodeValueToString();
        break;
    }

    default:
    {
        httpStatus = HttpStatusCode::InternalServerError;
        httpStatusLine = error.ErrorCodeValueToString();
        break;
    }
    }
}