From 3232579f29d1c91e70e7dc76305d6589c4acbaae Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sun, 14 Mar 2021 00:39:27 +0100 Subject: chore: get repos error in json mode --- src/repository/routes.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/repository/routes.rs b/src/repository/routes.rs index ebfff8e..6b3a942 100644 --- a/src/repository/routes.rs +++ b/src/repository/routes.rs @@ -1,23 +1,21 @@ use crate::config::AppState; +use crate::errors::AppErrorResponse; use crate::repository::models::Repository; use actix_web::{web, HttpResponse, Responder}; use slog::info; async fn index(state: web::Data) -> impl Responder { let result = Repository::find_all(state.pool.clone()).await; + info!(state.log, "GET /repo/"); match result { - Ok(repos) => { - info!(state.log, "GET /repo/ 200"); - HttpResponse::Ok().json(repos) - } - _ => { - info!(state.log, "GET /repo/ 500"); - HttpResponse::BadRequest() - .body("Error trying to read all repositories from database") - } + Ok(repos) => HttpResponse::Ok().json(repos), + _ => HttpResponse::BadRequest().json(AppErrorResponse { + detail: "Error trying to read all repositories from database" + .to_string(), + }), } } pub fn config(cfg: &mut web::ServiceConfig) { - cfg.service(web::resource("/repo/").route(web::get().to(index))); + cfg.service(web::resource("/repo{_:/?}").route(web::get().to(index))) } -- cgit v1.2.3-18-g5258