mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-20 17:41:37 +00:00
Catch more HTTP API errors
This commit is contained in:
parent
44a42a177a
commit
aababf37a8
2 changed files with 36 additions and 31 deletions
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
use futures::{future, sync::oneshot, Future};
|
||||
use futures::{sync::oneshot, Future};
|
||||
|
||||
use hyper::{header, service::Service, Body, Method, Request, Response, StatusCode};
|
||||
use hyper::{service::Service, Body, Method, Request, StatusCode};
|
||||
use rbx_dom_weak::RbxId;
|
||||
|
||||
use crate::{
|
||||
|
|
@ -74,13 +74,10 @@ impl<F: ImfsFetcher> ApiService<F> {
|
|||
let input_cursor: u32 = match argument.parse() {
|
||||
Ok(v) => v,
|
||||
Err(err) => {
|
||||
return Box::new(future::ok(
|
||||
Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.header(header::CONTENT_TYPE, "text/plain")
|
||||
.body(Body::from(err.to_string()))
|
||||
.unwrap(),
|
||||
));
|
||||
return json(
|
||||
ErrorResponse::bad_request(format!("Malformed message cursor: {}", err)),
|
||||
StatusCode::BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -92,21 +89,16 @@ impl<F: ImfsFetcher> ApiService<F> {
|
|||
message_queue.subscribe(input_cursor, sender);
|
||||
}
|
||||
|
||||
Box::new(receiver.then(move |result| {
|
||||
match result {
|
||||
Box::new(receiver.then(move |result| match result {
|
||||
Ok((message_cursor, messages)) => json_ok(SubscribeResponse {
|
||||
session_id,
|
||||
message_cursor,
|
||||
messages,
|
||||
}),
|
||||
Err(_) => Box::new(future::ok(
|
||||
Response::builder()
|
||||
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||
.header(header::CONTENT_TYPE, "text/plain")
|
||||
.body(Body::from("Message queue disconnected sender!"))
|
||||
.unwrap(),
|
||||
)),
|
||||
}
|
||||
Err(_) => json(
|
||||
ErrorResponse::internal_error("Message queue disconnected sender"),
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
),
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
@ -117,13 +109,10 @@ impl<F: ImfsFetcher> ApiService<F> {
|
|||
let requested_ids = match requested_ids {
|
||||
Some(ids) => ids,
|
||||
None => {
|
||||
return Box::new(future::ok(
|
||||
Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.header(header::CONTENT_TYPE, "text/plain")
|
||||
.body(Body::from("Malformed ID list"))
|
||||
.unwrap(),
|
||||
));
|
||||
return json(
|
||||
ErrorResponse::bad_request("Malformed ID list"),
|
||||
StatusCode::BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -93,9 +93,25 @@ impl ErrorResponse {
|
|||
details: details.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bad_request<S: Into<String>>(details: S) -> Self {
|
||||
Self {
|
||||
kind: ErrorResponseKind::BadRequest,
|
||||
details: details.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn internal_error<S: Into<String>>(details: S) -> Self {
|
||||
Self {
|
||||
kind: ErrorResponseKind::InternalError,
|
||||
details: details.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum ErrorResponseKind {
|
||||
NotFound,
|
||||
BadRequest,
|
||||
InternalError,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue