Skip to content

NetworkError::Internal should use an enum instead of a string #36434

@jdm

Description

@jdm

Code like

// The spec advises failing here if reconnecting would be
// "futile", with no more specific advice; WPT tests
// consider a non-http(s) scheme to be futile.
match self.event_source.root().url.scheme() {
would benefit from our network errors having a reliable structure (which would allow us to implement helper methods like is_permanent_failure), rather than simply containing a user-readable string. We could move the strings to a Debug implementation on the enum instead.

/// Could be any of the internal errors, like unsupported scheme, connection errors, etc.
Internal(String),

However, code like

_ => NetworkError::Internal(error_string),
}
}
pub fn from_http_error(error: &HttpError) -> Self {
NetworkError::Internal(error.to_string())
}
makes this task more challenging than it first appears. I suppose it's still possible to have a catch-all variant that only contains a string.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions