View | Details | Raw Unified | Return to bug 24857
Collapse All | Expand All

(-)a/Koha/REST/V1/Biblios/Volumes.pm (-47 / +9 lines)
Lines 52-70 sub list { Link Here
52
        );
52
        );
53
    }
53
    }
54
    catch {
54
    catch {
55
        unless ( blessed $_ && $_->can('rethrow') ) {
55
        $c->unhandled_exception($_);
56
            return $c->render(
57
                status  => 500,
58
                openapi => {
59
                    error =>
60
                      "Something went wrong, check Koha logs for details."
61
                }
62
            );
63
        }
64
        return $c->render(
65
            status  => 500,
66
            openapi => { error => "$_" }
67
        );
68
    };
56
    };
69
}
57
}
70
58
Lines 100-111 sub get { Link Here
100
        }
88
        }
101
    }
89
    }
102
    catch {
90
    catch {
103
        return $c->render(
91
        $c->unhandled_exception($_);
104
            status  => 500,
105
            openapi => {
106
                error => "Something went wrong, check the logs ($_)."
107
            }
108
        );
109
    };
92
    };
110
}
93
}
111
94
Lines 137-158 sub add { Link Here
137
        if ( blessed($_) ) {
120
        if ( blessed($_) ) {
138
            my $to_api_mapping = Koha::Biblio::Volume->new->to_api_mapping;
121
            my $to_api_mapping = Koha::Biblio::Volume->new->to_api_mapping;
139
122
140
            if ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) {
123
            if ( $_->isa('Koha::Exceptions::Object::FKConstraint') and
124
                 $to_api_mapping->{ $_->broken_fk } eq 'biblio_id') {
141
                return $c->render(
125
                return $c->render(
142
                    status  => 409,
126
                    status  => 404,
143
                    openapi => {
127
                    openapi => { error => "Biblio not found" }
144
                        error => "Given " . $to_api_mapping->{ $_->broken_fk } . " does not exist"
145
                    }
146
                );
128
                );
147
            }
129
            }
148
        }
130
        }
149
131
150
        return $c->render(
132
        $c->unhandled_exception($_);
151
            status  => 500,
152
            openapi => {
153
                error => "Unhandled exception ($_)"
154
            }
155
        );
156
    };
133
    };
157
}
134
}
158
135
Lines 202-213 sub update { Link Here
202
            }
179
            }
203
        }
180
        }
204
181
205
        return $c->render(
182
        $c->unhandled_exception($_);
206
            status  => 500,
207
            openapi => {
208
                error => "Unhandled exception ($_)"
209
            }
210
        );
211
    };
183
    };
212
}
184
}
213
185
Lines 235-251 sub delete { Link Here
235
        return $c->render( status => 204, openapi => '');
207
        return $c->render( status => 204, openapi => '');
236
    }
208
    }
237
    catch {
209
    catch {
238
        unless ( blessed $_ && $_->can('rethrow') ) {
210
        $c->unhandled_exception($_);
239
            return $c->render(
240
                status  => 500,
241
                openapi => { error => "Something went wrong, check Koha logs for details." }
242
            );
243
        }
244
245
        return $c->render(
246
            status  => 500,
247
            openapi => { error => "$_" }
248
        );
249
    };
211
    };
250
}
212
}
251
213
(-)a/Koha/REST/V1/Biblios/Volumes/Items.pm (-18 / +3 lines)
Lines 103-114 sub add { Link Here
103
            }
103
            }
104
        }
104
        }
105
105
106
        return $c->render(
106
        $c->unhandled_exception($_);
107
            status  => 500,
108
            openapi => {
109
                error => "Unhandled exception ($_)"
110
            }
111
        );
112
    };
107
    };
113
}
108
}
114
109
Lines 144-164 sub delete { Link Here
144
        $item_link->delete;
139
        $item_link->delete;
145
        return $c->render(
140
        return $c->render(
146
            status  => 204,
141
            status  => 204,
147
            openapi => ''
142
            openapi => q{}
148
        );
143
        );
149
    }
144
    }
150
    catch {
145
    catch {
151
        unless ( blessed $_ && $_->can('rethrow') ) {
146
        $c->unhandled_exception($_);
152
            return $c->render(
153
                status  => 500,
154
                openapi => { error => "Something went wrong, check Koha logs for details." }
155
            );
156
        }
157
158
        return $c->render(
159
            status  => 500,
160
            openapi => { error => "$_" }
161
        );
162
    };
147
    };
163
}
148
}
164
149
(-)a/t/db_dependent/api/v1/volumes.t (-8 / +10 lines)
Lines 110-117 subtest 'volumes add() tests' => sub { Link Here
110
      ->status_is( 201, 'SWAGGER3.2.1' );
110
      ->status_is( 201, 'SWAGGER3.2.1' );
111
111
112
    # Invalid biblio id
112
    # Invalid biblio id
113
    $t->post_ok( "//$auth_userid:$password@/api/v1/biblios/XXX/volumes" => json => $volume )
113
    {   # hide useless warnings
114
        ->status_is( 409, 'SWAGGER3.2.1' );
114
        local *STDERR;
115
        open STDERR, '>', '/dev/null';
116
        $t->post_ok( "//$auth_userid:$password@/api/v1/biblios/XXX/volumes" => json => $volume )
117
            ->status_is( 404 );
118
        close STDERR;
119
    }
115
120
116
    $schema->storage->txn_rollback;
121
    $schema->storage->txn_rollback;
117
};
122
};
Lines 196-205 subtest 'volumes delete() tests' => sub { Link Here
196
      ->status_is(403);
201
      ->status_is(403);
197
202
198
    $t->delete_ok( "//$auth_userid:$password@/api/v1/biblios/XXX/volumes/$volume_id" )
203
    $t->delete_ok( "//$auth_userid:$password@/api/v1/biblios/XXX/volumes/$volume_id" )
199
        ->status_is(404);
204
      ->status_is(404);
200
205
201
    $t->delete_ok( "//$auth_userid:$password@/api/v1/biblios/$biblio_id/volumes/XXX" )
206
    $t->delete_ok( "//$auth_userid:$password@/api/v1/biblios/$biblio_id/volumes/XXX" )
202
        ->status_is(404);
207
      ->status_is(404);
203
208
204
    $schema->storage->txn_rollback;
209
    $schema->storage->txn_rollback;
205
};
210
};
Lines 239-251 subtest 'volume items add() + delete() tests' => sub { Link Here
239
    my $item_2_id = $item_2->id;
244
    my $item_2_id = $item_2->id;
240
245
241
    $t->post_ok( "//$userid:$password@/api/v1/biblios/{biblio_id}/volumes/$volume_id/items" => json => { item_id => $item_2->id } )
246
    $t->post_ok( "//$userid:$password@/api/v1/biblios/{biblio_id}/volumes/$volume_id/items" => json => { item_id => $item_2->id } )
242
        ->status_is( 201, 'SWAGGER3.2.1' );
247
      ->status_is( 201, 'SWAGGER3.2.1' );
243
248
244
    @items = $volume->items;
249
    @items = $volume->items;
245
    is( scalar(@items), 2, 'Volume now has two items');
250
    is( scalar(@items), 2, 'Volume now has two items');
246
251
247
    warn "A VOLUME ID: $volume_id";
248
    warn "A ITEM ID: $item_1_id";
249
    $t->delete_ok( "//$userid:$password@/api/v1/biblios/$biblio_id/volumes/$volume_id/items/$item_1_id" )
252
    $t->delete_ok( "//$userid:$password@/api/v1/biblios/$biblio_id/volumes/$volume_id/items/$item_1_id" )
250
        ->status_is(204, 'SWAGGER3.2.4')
253
        ->status_is(204, 'SWAGGER3.2.4')
251
        ->content_is('', 'SWAGGER3.3.4');
254
        ->content_is('', 'SWAGGER3.3.4');
252
- 

Return to bug 24857