tangled
alpha
login
or
join now
microcosm.blue
/
microcosm-rs
65
fork
atom
Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm
65
fork
atom
overview
issues
8
pulls
2
pipelines
proxy back upstream BadRequests
bad-example.com
7 months ago
fa9bc656
f427071e
+43
-8
2 changed files
expand all
collapse all
unified
split
slingshot
src
record.rs
server.rs
+2
-3
slingshot/src/record.rs
···
58
58
59
59
#[derive(Debug, Deserialize)]
60
60
pub struct ErrorResponseObject {
61
61
-
error: String,
62
62
-
#[allow(dead_code)]
63
63
-
message: String,
61
61
+
pub error: String,
62
62
+
pub message: String,
64
63
}
65
64
66
65
#[derive(Clone)]
+41
-5
slingshot/src/server.rs
···
1
1
-
use crate::{CachedRecord, Identity, Repo, error::ServerError};
1
1
+
use crate::{
2
2
+
CachedRecord, ErrorResponseObject, Identity, Repo,
3
3
+
error::{RecordError, ServerError},
4
4
+
};
2
5
use atrium_api::types::string::{Cid, Did, Handle, Nsid, RecordKey};
3
6
use foyer::HybridCache;
4
7
use serde::Serialize;
···
201
204
202
205
let at_uri = format!("at://{}/{}/{}", &*did, &*collection, &*rkey);
203
206
204
204
-
let entry = self
207
207
+
let fr = self
205
208
.cache
206
209
.fetch(at_uri.clone(), {
207
210
let cid = cid.clone();
···
213
216
.map_err(|e| foyer::Error::Other(Box::new(e)))
214
217
}
215
218
})
216
216
-
.await
217
217
-
.unwrap(); // todo
219
219
+
.await;
218
220
219
219
-
// TODO: actual 404
221
221
+
let entry = match fr {
222
222
+
Ok(e) => e,
223
223
+
Err(foyer::Error::Other(e)) => {
224
224
+
let record_error = match e.downcast::<RecordError>() {
225
225
+
Ok(e) => e,
226
226
+
Err(e) => {
227
227
+
log::error!("error (foyer other) getting cache entry, {e:?}");
228
228
+
return GetRecordResponse::ServerError(xrpc_error(
229
229
+
"ServerError",
230
230
+
"sorry, something went wrong",
231
231
+
));
232
232
+
}
233
233
+
};
234
234
+
let RecordError::UpstreamBadRequest(ErrorResponseObject { error, message }) =
235
235
+
*record_error
236
236
+
else {
237
237
+
log::error!("RecordError getting cache entry, {record_error:?}");
238
238
+
return GetRecordResponse::ServerError(xrpc_error(
239
239
+
"ServerError",
240
240
+
"sorry, something went wrong",
241
241
+
));
242
242
+
};
243
243
+
return GetRecordResponse::BadRequest(xrpc_error(
244
244
+
error,
245
245
+
format!("Upstream bad request: {message}"),
246
246
+
));
247
247
+
}
248
248
+
Err(e) => {
249
249
+
log::error!("error (foyer) getting cache entry, {e:?}");
250
250
+
return GetRecordResponse::ServerError(xrpc_error(
251
251
+
"ServerError",
252
252
+
"sorry, something went wrong",
253
253
+
));
254
254
+
}
255
255
+
};
220
256
221
257
match *entry {
222
258
CachedRecord::Found(ref raw) => {