From 61f582554fb1cebfe263ed60a18ec3fad8a02dd3 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sun, 10 Mar 2019 13:50:28 +0100 Subject: [PATCH] Return a proper API response when booking amount for consume/open is > current stock amount (references #170) --- grocy.openapi.json | 4 ++-- services/StockService.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/grocy.openapi.json b/grocy.openapi.json index 2d9f6647..5927f4c0 100644 --- a/grocy.openapi.json +++ b/grocy.openapi.json @@ -1185,7 +1185,7 @@ } }, "400": { - "description": "The operation was not successful (possible errors are: Not existing product, invalid transaction type)", + "description": "The operation was not successful (possible errors are: Not existing product, invalid transaction type, given amount > current stock amount)", "content": { "application/json": { "schema": { @@ -1311,7 +1311,7 @@ } }, "400": { - "description": "The operation was not successful (possible errors are: Not existing product)", + "description": "The operation was not successful (possible errors are: Not existing product, given amount > current unopened stock amount)", "content": { "application/json": { "schema": { diff --git a/services/StockService.php b/services/StockService.php index 9773e941..6abc247c 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -221,7 +221,7 @@ class StockService extends BaseService if ($amount > $productStockAmount) { - return false; + throw new \Exception('Amount to be consumed cannot be > current stock amount'); } if ($specificStockEntryId !== 'default') @@ -347,7 +347,7 @@ class StockService extends BaseService if ($amount > $productStockAmountUnopened) { - return false; + throw new \Exception('Amount to be opened cannot be > current unopened stock amount'); } if ($specificStockEntryId !== 'default')