Skip to content

Commit 7b3a8f7

Browse files
committed
fix pg errors being reported as user errors
We had some out of shared memory errors being reported to the user. I will look into actually fixing the memory issues later.
1 parent b46e113 commit 7b3a8f7

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

be/src/api.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,15 @@ impl From<deadpool_postgres::PoolError> for Error {
192192

193193
impl From<tokio_postgres::Error> for Error {
194194
fn from(err: tokio_postgres::Error) -> Self {
195-
match err.as_db_error() {
196-
Some(e) => Error::User(e.message().to_string()),
197-
None => Error::User(err.to_string()),
195+
if let Some(code) = err.code() {
196+
let code = code.code();
197+
// https://www.postgresql.org/docs/current/errcodes-appendix.html
198+
if code.starts_with("53") || code.starts_with("54") {
199+
return Error::Server(err.into());
200+
}
201+
return Error::User(err.to_string());
198202
}
203+
Error::Server(err.into())
199204
}
200205
}
201206

0 commit comments

Comments
 (0)