Lines 18-23
package Koha::REST::V1::Cities;
Link Here
|
18 |
use Mojo::Base 'Mojolicious::Controller'; |
18 |
use Mojo::Base 'Mojolicious::Controller'; |
19 |
|
19 |
|
20 |
use Koha::Cities; |
20 |
use Koha::Cities; |
|
|
21 |
use Koha::Exceptions; |
21 |
|
22 |
|
22 |
use Try::Tiny; |
23 |
use Try::Tiny; |
23 |
|
24 |
|
Lines 38-51
sub list {
Link Here
|
38 |
return $c->render( status => 200, openapi => $cities ); |
39 |
return $c->render( status => 200, openapi => $cities ); |
39 |
} |
40 |
} |
40 |
catch { |
41 |
catch { |
41 |
if ( $_->isa('DBIx::Class::Exception') ) { |
42 |
Koha::Exceptions::rethrow_exception($_); |
42 |
return $c->render( status => 500, |
|
|
43 |
openapi => { error => $_->{msg} } ); |
44 |
} |
45 |
else { |
46 |
return $c->render( status => 500, |
47 |
openapi => { error => "Something went wrong, check the logs."} ); |
48 |
} |
49 |
}; |
43 |
}; |
50 |
|
44 |
|
51 |
} |
45 |
} |
Lines 79-96
sub add {
Link Here
|
79 |
return $c->render( status => 200, openapi => _to_api($city->TO_JSON) ); |
73 |
return $c->render( status => 200, openapi => _to_api($city->TO_JSON) ); |
80 |
} |
74 |
} |
81 |
catch { |
75 |
catch { |
82 |
if ( $_->isa('DBIx::Class::Exception') ) { |
76 |
Koha::Exceptions::rethrow_exception($_); |
83 |
return $c->render( |
|
|
84 |
status => 500, |
85 |
openapi => { error => $_->{msg} } |
86 |
); |
87 |
} |
88 |
else { |
89 |
return $c->render( |
90 |
status => 500, |
91 |
openapi => { error => "Something went wrong, check the logs." } |
92 |
); |
93 |
} |
94 |
}; |
77 |
}; |
95 |
} |
78 |
} |
96 |
|
79 |
|
Lines 115-128
sub update {
Link Here
|
115 |
return $c->render( status => 200, openapi => _to_api($city->TO_JSON) ); |
98 |
return $c->render( status => 200, openapi => _to_api($city->TO_JSON) ); |
116 |
} |
99 |
} |
117 |
catch { |
100 |
catch { |
118 |
if ( $_->isa('Koha::Exceptions::Object') ) { |
101 |
if ( not defined $city ) { |
119 |
return $c->render( status => 500, |
102 |
return $c->render( status => 404, |
120 |
openapi => { error => $_->message } ); |
103 |
openapi => { error => "Object not found" } ); |
121 |
} |
|
|
122 |
else { |
123 |
return $c->render( status => 500, |
124 |
openapi => { error => "Something went wrong, check the logs."} ); |
125 |
} |
104 |
} |
|
|
105 |
Koha::Exceptions::rethrow_exception($_); |
126 |
}; |
106 |
}; |
127 |
} |
107 |
} |
128 |
|
108 |
|
Lines 144-157
sub delete {
Link Here
|
144 |
return $c->render( status => 200, openapi => "" ); |
124 |
return $c->render( status => 200, openapi => "" ); |
145 |
} |
125 |
} |
146 |
catch { |
126 |
catch { |
147 |
if ( $_->isa('DBIx::Class::Exception') ) { |
127 |
if ( not defined $city ) { |
148 |
return $c->render( status => 500, |
128 |
return $c->render( status => 404, |
149 |
openapi => { error => $_->{msg} } ); |
129 |
openapi => { error => "Object not found" } ); |
150 |
} |
|
|
151 |
else { |
152 |
return $c->render( status => 500, |
153 |
openapi => { error => "Something went wrong, check the logs."} ); |
154 |
} |
130 |
} |
|
|
131 |
Koha::Exceptions::rethrow_exception($_); |
155 |
}; |
132 |
}; |
156 |
} |
133 |
} |
157 |
|
134 |
|
158 |
- |
|
|