]> git.ktnx.net Git - lsl.git/blobdiff - lib/App/LazyShoppingList/API.pm
return exception responses as JSON
[lsl.git] / lib / App / LazyShoppingList / API.pm
index c828974fa5782d4c2e94e12bf3835f2ddf9f0967..84e7fad4ace3775c82073ee7fdac6a6ae8e53370 100644 (file)
@@ -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;
 
@@ -66,8 +66,13 @@ sub increment_lists_version($dbh) {
 }
 
 sub invalid_input($details = undef) {
-    status 400;
-    return "Invalid input" . ( defined($details) ? " ($details)" : '' );
+    return exception 400,
+        "Invalid input" . ( defined($details) ? " ($details)" : '' );
+}
+
+sub exception($http_code, $text) {
+    status $http_code;
+    return { exception => $text };
 }