Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ rquest = { version = "5.1.0", features = [
"cookies-preserve-order",
"cookies-multiple",
] }
rquest-util = { version = "2.3.0" }
rquest-util = { version = "2.2.0" }

[target.'cfg(not(target_env = "msvc"))'.dependencies]
jemallocator = { package = "tikv-jemallocator", version = "0.6", features = [
Expand Down
65 changes: 65 additions & 0 deletions rnet.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2785,3 +2785,68 @@ async def websocket(
asyncio.run(run())
```
"""

class DNSResolverError(RuntimeError):
r"""
An error occurred while resolving a DNS name.
"""

class BodyError(Exception):
r"""
An error occurred while processing the body of a request or response.
"""

class BuilderError(Exception):
r"""
An error occurred while building a request or response.
"""

class ConnectionError(Exception):
r"""
An error occurred while establishing a connection.
"""

class ConnectionResetError(Exception):
r"""
The connection was reset.
"""

class DecodingError(Exception):
r"""
An error occurred while decoding a response.
"""

class RedirectError(Exception):
r"""
An error occurred while following a redirect.
"""

class TimeoutError(Exception):
r"""
A timeout occurred while waiting for a response.
"""

class StatusError(Exception):
r"""
An error occurred while processing the status code of a response.
"""

class RequestError(Exception):
r"""
An error occurred while making a request.
"""

class UpgradeError(Exception):
r"""
An error occurred while upgrading a connection.
"""

class URLParseError(Exception):
r"""
An error occurred while parsing a URL.
"""

class MIMEParseError(Exception):
r"""
An error occurred while parsing a MIME type.
"""
26 changes: 12 additions & 14 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,19 @@ Potential solutions:
3) Change the order of operations to reference the instance before borrowing it.
"#;

create_exception!(exceptions, BorrowingError, PyRuntimeError);
create_exception!(exceptions, DNSResolverError, PyRuntimeError);

create_exception!(exceptions, BaseError, PyException);
create_exception!(exceptions, BodyError, BaseError);
create_exception!(exceptions, BuilderError, BaseError);
create_exception!(exceptions, ConnectionError, BaseError);
create_exception!(exceptions, DecodingError, BaseError);
create_exception!(exceptions, RedirectError, BaseError);
create_exception!(exceptions, TimeoutError, BaseError);
create_exception!(exceptions, StatusError, BaseError);
create_exception!(exceptions, RequestError, BaseError);
create_exception!(exceptions, UnknownError, BaseError);
create_exception!(exceptions, BodyError, PyException);
create_exception!(exceptions, BuilderError, PyException);
create_exception!(exceptions, ConnectionError, PyException);
create_exception!(exceptions, ConnectionResetError, PyException);
create_exception!(exceptions, DecodingError, PyException);
create_exception!(exceptions, RedirectError, PyException);
create_exception!(exceptions, TimeoutError, PyException);
create_exception!(exceptions, StatusError, PyException);
create_exception!(exceptions, RequestError, PyException);
create_exception!(exceptions, UpgradeError, PyException);

create_exception!(exceptions, HTTPMethodParseError, PyException);
create_exception!(exceptions, URLParseError, PyException);
create_exception!(exceptions, MIMEParseError, PyException);

Expand All @@ -44,7 +42,7 @@ macro_rules! wrap_error {
return $exception::new_err(format!(concat!(stringify!($variant), " error: {:?}"), $error));
}
)*
UnknownError::new_err(format!("Unknown error occurred: {:?}", $error))
UpgradeError::new_err(format!("error: {:?}", $error))
}
};
}
Expand Down Expand Up @@ -85,7 +83,7 @@ impl From<Error> for PyErr {
Error::RquestError(err) => wrap_error!(err,
is_body => BodyError,
is_connect => ConnectionError,
is_connection_reset => ConnectionError,
is_connection_reset => ConnectionResetError,
is_decode => DecodingError,
is_redirect => RedirectError,
is_timeout => TimeoutError,
Expand Down
19 changes: 19 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod typing;

use async_impl::{Client, Message, Response, Streamer, WebSocket};
use blocking::{BlockingClient, BlockingResponse, BlockingStreamer, BlockingWebSocket};
use error::*;
use pyo3::{prelude::*, pybacked::PyBackedStr};
use pyo3_async_runtimes::tokio::future_into_py;
use typing::param::{RequestParams, WebSocketParams};
Expand Down Expand Up @@ -169,6 +170,24 @@ fn rnet(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<BlockingWebSocket>()?;
m.add_class::<BlockingStreamer>()?;

let py = m.py();
m.add("DNSResolverError", py.get_type::<DNSResolverError>())?;
m.add("BodyError", py.get_type::<BodyError>())?;
m.add("BuilderError", py.get_type::<BuilderError>())?;
m.add("ConnectionError", py.get_type::<ConnectionError>())?;
m.add(
"ConnectionResetError",
py.get_type::<ConnectionResetError>(),
)?;
m.add("DecodingError", py.get_type::<DecodingError>())?;
m.add("RedirectError", py.get_type::<RedirectError>())?;
m.add("TimeoutError", py.get_type::<TimeoutError>())?;
m.add("StatusError", py.get_type::<StatusError>())?;
m.add("RequestError", py.get_type::<RequestError>())?;
m.add("UpgradeError", py.get_type::<UpgradeError>())?;
m.add("URLParseError", py.get_type::<URLParseError>())?;
m.add("MIMEParseError", py.get_type::<MIMEParseError>())?;

m.add_function(wrap_pyfunction!(get, m)?)?;
m.add_function(wrap_pyfunction!(post, m)?)?;
m.add_function(wrap_pyfunction!(put, m)?)?;
Expand Down
Loading