fix some error status codes
This commit is contained in:
parent
4018121e51
commit
ae39636cd2
@ -72,7 +72,6 @@ pub async fn websocket_handler(
|
|||||||
/// Rate limit and billing based on the api key in the url.
|
/// Rate limit and billing based on the api key in the url.
|
||||||
/// Can optionally authorized based on origin, referer, or user agent.
|
/// Can optionally authorized based on origin, referer, or user agent.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
|
|
||||||
pub async fn websocket_handler_with_key(
|
pub async fn websocket_handler_with_key(
|
||||||
Extension(app): Extension<Arc<Web3ProxyApp>>,
|
Extension(app): Extension<Arc<Web3ProxyApp>>,
|
||||||
ClientIp(ip): ClientIp,
|
ClientIp(ip): ClientIp,
|
||||||
@ -94,6 +93,9 @@ pub async fn websocket_handler_with_key(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
// TODO: turn this logging down!
|
||||||
|
info!("websocket_handler_with_key {:?}", authorization);
|
||||||
|
|
||||||
let authorization = Arc::new(authorization);
|
let authorization = Arc::new(authorization);
|
||||||
|
|
||||||
match ws_upgrade {
|
match ws_upgrade {
|
||||||
@ -102,15 +104,19 @@ pub async fn websocket_handler_with_key(
|
|||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// if no websocket upgrade, this is probably a user loading the url with their browser
|
// if no websocket upgrade, this is probably a user loading the url with their browser
|
||||||
|
|
||||||
|
// TODO: rate limit here? key_is_authorized might be enough
|
||||||
|
|
||||||
match (
|
match (
|
||||||
&app.config.redirect_public_url,
|
&app.config.redirect_public_url,
|
||||||
&app.config.redirect_rpc_key_url,
|
&app.config.redirect_rpc_key_url,
|
||||||
authorization.checks.rpc_key_id,
|
authorization.checks.rpc_key_id,
|
||||||
) {
|
) {
|
||||||
(None, None, _) => Err(anyhow::anyhow!(
|
(None, None, _) => Err(FrontendErrorResponse::StatusCode(
|
||||||
"redirect_rpc_key_url not set. only websockets work here"
|
StatusCode::BAD_REQUEST,
|
||||||
)
|
"this page is for rpcs".to_string(),
|
||||||
.into()),
|
None,
|
||||||
|
)),
|
||||||
(Some(redirect_public_url), _, None) => {
|
(Some(redirect_public_url), _, None) => {
|
||||||
Ok(Redirect::to(redirect_public_url).into_response())
|
Ok(Redirect::to(redirect_public_url).into_response())
|
||||||
}
|
}
|
||||||
@ -118,8 +124,12 @@ pub async fn websocket_handler_with_key(
|
|||||||
let reg = Handlebars::new();
|
let reg = Handlebars::new();
|
||||||
|
|
||||||
if authorization.checks.rpc_key_id.is_none() {
|
if authorization.checks.rpc_key_id.is_none() {
|
||||||
// TODO: i think this is impossible
|
// i don't think this is possible
|
||||||
Err(anyhow::anyhow!("only authenticated websockets work here").into())
|
Err(FrontendErrorResponse::StatusCode(
|
||||||
|
StatusCode::UNAUTHORIZED,
|
||||||
|
"AUTHORIZATION header required".to_string(),
|
||||||
|
None,
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
let redirect_rpc_key_url = reg
|
let redirect_rpc_key_url = reg
|
||||||
.render_template(
|
.render_template(
|
||||||
|
Loading…
Reference in New Issue
Block a user