diff --git a/quaint/src/connector/postgres/native/websocket.rs b/quaint/src/connector/postgres/native/websocket.rs index fba6742decc..7e572e3a161 100644 --- a/quaint/src/connector/postgres/native/websocket.rs +++ b/quaint/src/connector/postgres/native/websocket.rs @@ -2,7 +2,12 @@ use std::str::FromStr; use async_tungstenite::{ tokio::connect_async, - tungstenite::{self, client::IntoClientRequest, http::HeaderValue, Error as TungsteniteError}, + tungstenite::{ + self, + client::IntoClientRequest, + http::{HeaderValue, StatusCode}, + Error as TungsteniteError, + }, }; use futures::FutureExt; use tokio_postgres::{Client, Config, NoTls}; @@ -10,7 +15,7 @@ use ws_stream_tungstenite::WsStream; use crate::{ connector::PostgresWebSocketUrl, - error::{self, Error, ErrorKind, NativeErrorKind}, + error::{self, Error, ErrorKind, Name, NativeErrorKind}, }; const CONNECTION_PARAMS_HEADER: &str = "Prisma-Connection-Parameters"; @@ -60,6 +65,12 @@ impl From for error::Error { message: tls_error.to_string(), })), + TungsteniteError::Http(response) if response.status() == StatusCode::UNAUTHORIZED => { + Error::builder(ErrorKind::DatabaseAccessDenied { + db_name: Name::Unavailable, + }) + } + _ => Error::builder(ErrorKind::Native(NativeErrorKind::ConnectionError(Box::new(value)))), }; diff --git a/schema-engine/connectors/sql-schema-connector/src/flavour/postgres.rs b/schema-engine/connectors/sql-schema-connector/src/flavour/postgres.rs index 9c3feef989b..79b2b7d7f65 100644 --- a/schema-engine/connectors/sql-schema-connector/src/flavour/postgres.rs +++ b/schema-engine/connectors/sql-schema-connector/src/flavour/postgres.rs @@ -51,10 +51,10 @@ impl MigratePostgresUrl { "Required `apiKey` query string parameter was not provided in a connection URL", )); }; - PostgresUrl::new_websocket(ws_url, api_key.into_owned()).map_err(ConnectorError::url_parse_error)? + PostgresUrl::new_websocket(ws_url, api_key.into_owned()) } else { - PostgresUrl::new_native(url).map_err(ConnectorError::url_parse_error)? - }; + PostgresUrl::new_native(url) + }.map_err(ConnectorError::url_parse_error)?; Ok(Self(postgres_url)) }