X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=lib%2FApp%2FLazyShoppingList%2FAPI.pm;h=36f7e6863aa1f533c0371d956e1aa1b4630b2743;hb=5a3a2e34bd2f7286ed73cded06c3cc2000d0a5f3;hp=c828974fa5782d4c2e94e12bf3835f2ddf9f0967;hpb=b28adff9a0ae8c3359e2bcf315479b46ad90306b;p=lsl.git diff --git a/lib/App/LazyShoppingList/API.pm b/lib/App/LazyShoppingList/API.pm index c828974..36f7e68 100644 --- a/lib/App/LazyShoppingList/API.pm +++ b/lib/App/LazyShoppingList/API.pm @@ -9,7 +9,7 @@ use Exporter qw(import); our $VERSION = '0.1'; our @EXPORT = qw( &get_database &get_lists_version &increment_lists_version - &invalid_input ); + &invalid_input exception ); use Dancer2::Plugin::DBIC; @@ -65,9 +65,14 @@ sub increment_lists_version($dbh) { return $g->lists_version; } +sub exception($http_code, $text) { + status $http_code; + return { exception => $text }; +} + sub invalid_input($details = undef) { - status 400; - return "Invalid input" . ( defined($details) ? " ($details)" : '' ); + return exception 400, + "Invalid input" . ( defined($details) ? " ($details)" : '' ); }