Avoid panics (#392)
- Use `Result` as much as possible - Display errors instead of panicking TODO (maybe in another PR? this one is already quite big): - Find a way to merge Ructe/ErrorPage types, so that we can have routes returning `Result<X, ErrorPage>` instead of panicking when we have an `Error` - Display more details about the error, to make it easier to debug (sorry, this isn't going to be fun to review, the diff is huge, but it is always the same changes)
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
use canapi::{Error, Provider};
|
||||
use canapi::{Error as ApiError, Provider};
|
||||
use chrono::NaiveDateTime;
|
||||
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||
|
||||
use plume_api::apps::AppEndpoint;
|
||||
use plume_common::utils::random_hex;
|
||||
use schema::apps;
|
||||
use Connection;
|
||||
use {Connection, Error, Result, ApiResult};
|
||||
|
||||
#[derive(Clone, Queryable)]
|
||||
pub struct App {
|
||||
@@ -31,7 +31,7 @@ pub struct NewApp {
|
||||
impl Provider<Connection> for App {
|
||||
type Data = AppEndpoint;
|
||||
|
||||
fn get(_conn: &Connection, _id: i32) -> Result<AppEndpoint, Error> {
|
||||
fn get(_conn: &Connection, _id: i32) -> ApiResult<AppEndpoint> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ impl Provider<Connection> for App {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn create(conn: &Connection, data: AppEndpoint) -> Result<AppEndpoint, Error> {
|
||||
fn create(conn: &Connection, data: AppEndpoint) -> ApiResult<AppEndpoint> {
|
||||
let client_id = random_hex();
|
||||
|
||||
let client_secret = random_hex();
|
||||
@@ -52,7 +52,7 @@ impl Provider<Connection> for App {
|
||||
redirect_uri: data.redirect_uri,
|
||||
website: data.website,
|
||||
},
|
||||
);
|
||||
).map_err(|_| ApiError::NotFound("Couldn't register app".into()))?;
|
||||
|
||||
Ok(AppEndpoint {
|
||||
id: Some(app.id),
|
||||
@@ -64,7 +64,7 @@ impl Provider<Connection> for App {
|
||||
})
|
||||
}
|
||||
|
||||
fn update(_conn: &Connection, _id: i32, _new_data: AppEndpoint) -> Result<AppEndpoint, Error> {
|
||||
fn update(_conn: &Connection, _id: i32, _new_data: AppEndpoint) -> ApiResult<AppEndpoint> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user