Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions packages/common/api-builder/src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::anyhow;
use axum::{
extract::{
Request,
rejection::{ExtensionRejection, JsonRejection},
rejection::{ExtensionRejection, JsonRejection, PathRejection},
{FromRequest, FromRequestParts},
},
response::IntoResponse,
Expand Down Expand Up @@ -102,7 +102,36 @@ where
.map(|ext| Extension(ext.0))
.map_err(|err| {
ExtractorError(
anyhow!("developer error: extension error: {}", err.body_text()).into(),
ApiBadRequest {
reason: err.body_text(),
}
.build()
.into(),
)
})
}
}

pub struct Path<T>(pub T);

impl<S, T> FromRequestParts<S> for Path<T>
where
axum::extract::Path<T>: FromRequestParts<S, Rejection = PathRejection>,
S: Send + Sync,
{
type Rejection = ExtractorError;

async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
axum::extract::Path::<T>::from_request_parts(parts, state)
.await
.map(|ext| Path(ext.0))
.map_err(|err| {
ExtractorError(
ApiBadRequest {
reason: err.body_text(),
}
.build()
.into(),
)
})
}
Expand Down
3 changes: 1 addition & 2 deletions packages/common/api-builder/src/wrappers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::Result;
use axum::{
body::Bytes,
extract::Path,
response::IntoResponse,
routing::{
delete as axum_delete, get as axum_get, patch as axum_patch, post as axum_post,
Expand All @@ -14,7 +13,7 @@ use std::future::Future;
use crate::{
context::ApiCtx,
error_response::ApiError,
extract::{Extension, Json, Query},
extract::{Extension, Json, Path, Query},
};

/// Macro to generate wrapper functions for HTTP methods
Expand Down
3 changes: 1 addition & 2 deletions packages/core/api-public/src/actors/delete.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use anyhow::Result;
use axum::{
extract::Path,
http::HeaderMap,
response::{IntoResponse, Response},
};
use rivet_api_builder::{
ApiError,
extract::{Extension, Json, Query},
extract::{Extension, Json, Path, Query},
};
use rivet_api_util::request_remote_datacenter_raw;
use rivet_util::Id;
Expand Down
3 changes: 1 addition & 2 deletions packages/core/api-public/src/runner_configs.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use anyhow::Result;
use axum::{
extract::Path,
http::HeaderMap,
response::{IntoResponse, Response},
};
use rivet_api_builder::{
ApiError,
extract::{Extension, Json, Query},
extract::{Extension, Json, Path, Query},
};

use rivet_api_peer::runner_configs::*;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/api-public/src/ui.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use axum::{
extract::Path,
http::{StatusCode, header},
response::{IntoResponse, Response},
};
use include_dir::{Dir, include_dir};
use rivet_api_builder::extract::Path;

static UI_DIR: Dir<'_> = include_dir!("$OUT_DIR/ui");

Expand Down
Loading