diff --git a/bookshop/srv/cat-service.js b/bookshop/srv/cat-service.js index 40896f4b..e1a26711 100644 --- a/bookshop/srv/cat-service.js +++ b/bookshop/srv/cat-service.js @@ -18,7 +18,7 @@ class CatalogService extends cds.ApplicationService { init() { // Validate input data if (!book) return req.error (404, `Book #${id} doesn't exist`) if (quantity < 1) return req.error (400, `quantity has to be 1 or more`) - if (quantity > book.stock) return req.error (409, `${quantity} exceeds stock for book #${id}`) + if (quantity > book.stock) return req.error (409, "ORDER_EXCEEDS_STOCK", [quantity, id]) // Reduce stock in database and return updated stock value await UPDATE (Books, id) .with ({ stock: book.stock -= quantity }) diff --git a/bookshop/srv/i18n/messages.properties b/bookshop/srv/i18n/messages.properties new file mode 100644 index 00000000..c9c2641c --- /dev/null +++ b/bookshop/srv/i18n/messages.properties @@ -0,0 +1 @@ +ORDER_EXCEEDS_STOCK={0} exceeds stock for book #{1} \ No newline at end of file