Skip to content

Commit

Permalink
Handle unauthorized error
Browse files Browse the repository at this point in the history
  • Loading branch information
SevInf committed Oct 2, 2024
1 parent e99704a commit 7c69bf5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
15 changes: 13 additions & 2 deletions quaint/src/connector/postgres/native/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ 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};
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";
Expand Down Expand Up @@ -60,6 +65,12 @@ impl From<TungsteniteError> 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)))),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Check warning on line 54 in schema-engine/connectors/sql-schema-connector/src/flavour/postgres.rs

View workflow job for this annotation

GitHub Actions / rustfmt

Diff in /home/runner/work/prisma-engines/prisma-engines/schema-engine/connectors/sql-schema-connector/src/flavour/postgres.rs
} 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))
}
Expand Down

0 comments on commit 7c69bf5

Please sign in to comment.