Skip to content

Commit fb2e6ac

Browse files
committed
wip
1 parent c6b741e commit fb2e6ac

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

ntex/src/client/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ pub enum ClientError {
269269
impl Clone for ClientError {
270270
fn clone(&self) -> ClientError {
271271
match self {
272-
ClientError::Url(err) => ClientError::Url(err.clone()),
272+
ClientError::Url(err) => ClientError::Url(*err),
273273
ClientError::Connect(err) => ClientError::Connect(err.clone()),
274274
ClientError::Request(err) => ClientError::Request(err.clone()),
275275
ClientError::Response(err) => ClientError::Response(*err),

ntex/src/web/error.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! Web error
22
use std::{cell::RefCell, fmt, io::Write, marker::PhantomData};
33

4-
use thiserror::Error;
5-
64
pub use ntex_http::error::Error as HttpError;
75
pub use serde_json::error::Error as JsonError;
86
#[cfg(feature = "url")]
@@ -78,14 +76,14 @@ where
7876
}
7977

8078
/// Errors which can occur when attempting to work with `State` extractor
81-
#[derive(Error, Debug, Copy, Clone, PartialEq, Eq)]
79+
#[derive(Debug, Copy, Clone, PartialEq, Eq, thiserror::Error)]
8280
pub enum StateExtractorError {
8381
#[error("App state is not configured, to configure use App::state()")]
8482
NotConfigured,
8583
}
8684

8785
/// Errors which can occur when attempting to generate resource uri.
88-
#[derive(Error, Debug, Copy, Clone, PartialEq, Eq)]
86+
#[derive(Debug, Copy, Clone, PartialEq, Eq, thiserror::Error)]
8987
pub enum UrlGenerationError {
9088
/// Resource not found
9189
#[error("Resource not found")]
@@ -100,7 +98,7 @@ pub enum UrlGenerationError {
10098
}
10199

102100
/// A set of errors that can occur during parsing urlencoded payloads
103-
#[derive(Error, Debug)]
101+
#[derive(Debug, thiserror::Error)]
104102
pub enum UrlencodedError {
105103
/// Cannot decode chunked transfer encoding
106104
#[error("Cannot decode chunked transfer encoding")]
@@ -125,7 +123,7 @@ pub enum UrlencodedError {
125123
}
126124

127125
/// A set of errors that can occur during parsing json payloads
128-
#[derive(Error, Debug)]
126+
#[derive(Debug, thiserror::Error)]
129127
pub enum JsonPayloadError {
130128
/// Payload size is bigger than allowed. (default: 32kB)
131129
#[error("Json payload size is bigger than allowed")]
@@ -142,22 +140,22 @@ pub enum JsonPayloadError {
142140
}
143141

144142
/// A set of errors that can occur during parsing request paths
145-
#[derive(Error, Debug)]
143+
#[derive(Debug, thiserror::Error)]
146144
pub enum PathError {
147145
/// Deserialize error
148146
#[error("Path deserialize error: {0}")]
149147
Deserialize(#[from] serde::de::value::Error),
150148
}
151149

152150
/// A set of errors that can occur during parsing query strings
153-
#[derive(Error, Debug)]
151+
#[derive(Debug, thiserror::Error)]
154152
pub enum QueryPayloadError {
155153
/// Deserialize error
156154
#[error("Query deserialize error: {0}")]
157155
Deserialize(#[from] serde::de::value::Error),
158156
}
159157

160-
#[derive(Error, Debug)]
158+
#[derive(Debug, thiserror::Error)]
161159
pub enum PayloadError {
162160
/// Http error.
163161
#[error("{0:?}")]

ntex/src/ws/error.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
//! WebSocket protocol related errors.
22
use std::io;
33

4-
use thiserror::Error;
5-
64
use crate::http::error::{DecodeError, EncodeError, HttpError, ResponseError};
75
use crate::http::{Response, StatusCode, header::ALLOW, header::HeaderValue};
86
use crate::{connect::ConnectError, util::Either, util::clone_io_error};
97

108
use super::OpCode;
119

1210
/// Websocket service errors
13-
#[derive(Error, Debug)]
11+
#[derive(Debug, thiserror::Error)]
1412
pub enum WsError<E> {
1513
#[error("Service error")]
1614
Service(E),
@@ -29,7 +27,7 @@ pub enum WsError<E> {
2927
}
3028

3129
/// Websocket protocol errors
32-
#[derive(Error, Copy, Clone, Debug)]
30+
#[derive(Copy, Clone, Debug, thiserror::Error)]
3331
pub enum ProtocolError {
3432
/// Received an unmasked frame from client
3533
#[error("Received an unmasked frame from client")]
@@ -61,7 +59,7 @@ pub enum ProtocolError {
6159
}
6260

6361
/// Websocket client error
64-
#[derive(Error, Clone, Debug)]
62+
#[derive(Clone, Debug, thiserror::Error)]
6563
pub enum WsClientBuilderError<E> {
6664
#[error("Cannot create connector {0}")]
6765
Connector(E),
@@ -76,7 +74,7 @@ pub enum WsClientBuilderError<E> {
7674
}
7775

7876
/// Websocket client error
79-
#[derive(Error, Debug)]
77+
#[derive(Debug, thiserror::Error)]
8078
pub enum WsClientError {
8179
/// Invalid request
8280
#[error("Invalid request")]
@@ -168,7 +166,7 @@ impl Clone for WsClientError {
168166
}
169167

170168
/// Websocket handshake errors
171-
#[derive(Error, Copy, Clone, PartialEq, Eq, Debug)]
169+
#[derive(Copy, Clone, PartialEq, Eq, Debug, thiserror::Error)]
172170
pub enum HandshakeError {
173171
/// Only get method is allowed
174172
#[error("Method not allowed")]

ntex/tests/web_server.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use flate2::Compression;
55
use flate2::read::GzDecoder;
66
use flate2::write::{GzEncoder, ZlibDecoder, ZlibEncoder};
77
use rand::{Rng, distr::Alphanumeric};
8-
use thiserror::Error;
98

109
use ntex::http::header::{
1110
ACCEPT_ENCODING, CONTENT_ENCODING, CONTENT_LENGTH, CONTENT_TYPE, ContentEncoding,
@@ -801,11 +800,11 @@ async fn test_slow_request() {
801800

802801
#[ntex::test]
803802
async fn test_custom_error() {
804-
#[derive(Error, Debug)]
803+
#[derive(Debug, thiserror::Error)]
805804
#[error("TestError")]
806805
struct TestError;
807806

808-
#[derive(Error, Debug)]
807+
#[derive(Debug, thiserror::Error)]
809808
#[error("JsonContainer({0})")]
810809
struct JsonContainer(Box<dyn WebResponseError<JsonRenderer>>);
811810

0 commit comments

Comments
 (0)