Skip to content

Commit 9227a0c

Browse files
committed
Translate DB errors
1 parent 5d5caac commit 9227a0c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

postgres-tokio/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub use postgres_shared::error;
2020
#[doc(inline)]
2121
pub use postgres_shared::params;
2222

23-
use error::ConnectError;
23+
use error::{ConnectError, DbError};
2424
use params::{ConnectParams, IntoConnectParams};
2525
use stream::PostgresStream;
2626

@@ -190,6 +190,9 @@ impl Connection {
190190
}
191191
}
192192
}
193+
backend::Message::ErrorResponse(body) => {
194+
DbError::new_connect(&mut body.fields())
195+
}
193196
_ => Err(bad_message()),
194197
};
195198

@@ -212,6 +215,9 @@ impl Connection {
212215
.and_then(|(m, s)| {
213216
match m {
214217
backend::Message::AuthenticationOk => Ok(Connection(s)),
218+
backend::Message::ErrorResponse(body) => {
219+
DbError::new_connect(&mut body.fields())
220+
}
215221
_ => Err(bad_message()),
216222
}
217223
})
@@ -229,6 +235,9 @@ impl Connection {
229235
Either::A(Connection(s).finish_startup())
230236
}
231237
backend::Message::ReadyForQuery(_) => Either::B(Ok(Connection(s)).into_future()),
238+
backend::Message::ErrorResponse(body) => {
239+
Either::B(DbError::new_connect(&mut body.fields()).into_future())
240+
}
232241
_ => Either::B(Err(bad_message()).into_future()),
233242
}
234243
})

0 commit comments

Comments
 (0)