From a338f5af5da2e67a5ea614628c41b19a604236e0 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Tue, 14 Mar 2017 18:19:58 +0200 Subject: [PATCH] Bug 18206: Use this feature for cities To test: 1. prove t/db_dependent/api/v1/cities.t --- Koha/REST/V1/Cities.pm | 37 +++++-------------------------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/Koha/REST/V1/Cities.pm b/Koha/REST/V1/Cities.pm index 3003e3a..a1a13b4 100644 --- a/Koha/REST/V1/Cities.pm +++ b/Koha/REST/V1/Cities.pm @@ -21,6 +21,7 @@ use Mojo::Base 'Mojolicious::Controller'; use Koha::City; use Koha::Cities; +use Koha::Exceptions; use Try::Tiny; @@ -40,14 +41,7 @@ sub list { return $c->render( status => 200, openapi => $cities ); } catch { - if ( $_->isa('DBIx::Class::Exception') ) { - return $c->render( status => 500, - openapi => { error => $_->{msg} } ); - } - else { - return $c->render( status => 500, - openapi => { error => "Something went wrong, check the logs."} ); - } + Koha::Exceptions::rethrow_exception($_); }; } @@ -74,14 +68,7 @@ sub add { return $c->render( status => 200, openapi => $city ); } catch { - if ( $_->isa('DBIx::Class::Exception') ) { - return $c->render( status => 500, - openapi => { error => $_->{msg} } ); - } - else { - return $c->render( status => 500, - openapi => { error => "Something went wrong, check the logs."} ); - } + Koha::Exceptions::rethrow_exception($_); }; } @@ -102,14 +89,7 @@ sub update { return $c->render( status => 404, openapi => { error => "Object not found" } ); } - elsif ( $_->isa('Koha::Exceptions::Object') ) { - return $c->render( status => 500, - openapi => { error => $_->message } ); - } - else { - return $c->render( status => 500, - openapi => { error => "Something went wrong, check the logs."} ); - } + Koha::Exceptions::rethrow_exception($_); }; } @@ -129,14 +109,7 @@ sub delete { return $c->render( status => 404, openapi => { error => "Object not found" } ); } - elsif ( $_->isa('DBIx::Class::Exception') ) { - return $c->render( status => 500, - openapi => { error => $_->{msg} } ); - } - else { - return $c->render( status => 500, - openapi => { error => "Something went wrong, check the logs."} ); - } + Koha::Exceptions::rethrow_exception($_); }; } -- 1.9.1