mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-24 14:45:56 +00:00
Catch more HTTP API errors
This commit is contained in:
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
use std::{collections::HashMap, sync::Arc};
|
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 rbx_dom_weak::RbxId;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -74,13 +74,10 @@ impl<F: ImfsFetcher> ApiService<F> {
|
|||||||
let input_cursor: u32 = match argument.parse() {
|
let input_cursor: u32 = match argument.parse() {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
return Box::new(future::ok(
|
return json(
|
||||||
Response::builder()
|
ErrorResponse::bad_request(format!("Malformed message cursor: {}", err)),
|
||||||
.status(StatusCode::BAD_REQUEST)
|
StatusCode::BAD_REQUEST,
|
||||||
.header(header::CONTENT_TYPE, "text/plain")
|
);
|
||||||
.body(Body::from(err.to_string()))
|
|
||||||
.unwrap(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -92,21 +89,16 @@ impl<F: ImfsFetcher> ApiService<F> {
|
|||||||
message_queue.subscribe(input_cursor, sender);
|
message_queue.subscribe(input_cursor, sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
Box::new(receiver.then(move |result| {
|
Box::new(receiver.then(move |result| match result {
|
||||||
match result {
|
Ok((message_cursor, messages)) => json_ok(SubscribeResponse {
|
||||||
Ok((message_cursor, messages)) => json_ok(SubscribeResponse {
|
session_id,
|
||||||
session_id,
|
message_cursor,
|
||||||
message_cursor,
|
messages,
|
||||||
messages,
|
}),
|
||||||
}),
|
Err(_) => json(
|
||||||
Err(_) => Box::new(future::ok(
|
ErrorResponse::internal_error("Message queue disconnected sender"),
|
||||||
Response::builder()
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
),
|
||||||
.header(header::CONTENT_TYPE, "text/plain")
|
|
||||||
.body(Body::from("Message queue disconnected sender!"))
|
|
||||||
.unwrap(),
|
|
||||||
)),
|
|
||||||
}
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,13 +109,10 @@ impl<F: ImfsFetcher> ApiService<F> {
|
|||||||
let requested_ids = match requested_ids {
|
let requested_ids = match requested_ids {
|
||||||
Some(ids) => ids,
|
Some(ids) => ids,
|
||||||
None => {
|
None => {
|
||||||
return Box::new(future::ok(
|
return json(
|
||||||
Response::builder()
|
ErrorResponse::bad_request("Malformed ID list"),
|
||||||
.status(StatusCode::BAD_REQUEST)
|
StatusCode::BAD_REQUEST,
|
||||||
.header(header::CONTENT_TYPE, "text/plain")
|
);
|
||||||
.body(Body::from("Malformed ID list"))
|
|
||||||
.unwrap(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -93,9 +93,25 @@ impl ErrorResponse {
|
|||||||
details: details.into(),
|
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)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub enum ErrorResponseKind {
|
pub enum ErrorResponseKind {
|
||||||
NotFound,
|
NotFound,
|
||||||
|
BadRequest,
|
||||||
|
InternalError,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user