From 085a63aac4ef9216ac018312f6d89e8dec7c3c8c Mon Sep 17 00:00:00 2001 From: Pierre Fritsch Date: Fri, 10 Dec 2021 15:59:45 +0100 Subject: [PATCH 1/2] Localize the custom error message as documented in: https://cap.cloud.sap/docs/node.js/app-services#custom-errors Signed-off-by: Pierre Fritsch --- bookshop/srv/cat-service.js | 2 +- bookshop/srv/i18n/messages_en.properties | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 bookshop/srv/i18n/messages_en.properties diff --git a/bookshop/srv/cat-service.js b/bookshop/srv/cat-service.js index a9c629c0..e6b53a77 100644 --- a/bookshop/srv/cat-service.js +++ b/bookshop/srv/cat-service.js @@ -9,7 +9,7 @@ class CatalogService extends cds.ApplicationService { init(){ const {book,quantity} = req.data if (quantity < 1) return req.reject (400,`quantity has to be 1 or more`) let {stock} = await SELECT `stock` .from (Books,book) - if (quantity > stock) return req.reject (409,`${quantity} exceeds stock for book #${book}`) + if (quantity > stock) return req.reject (409, "ORDER_EXCEEDS_STOCK", [quantity, book]) await UPDATE (Books,book) .with ({ stock: stock -= quantity }) await this.emit ('OrderedBook', { book, quantity, buyer:req.user.id }) return { stock } diff --git a/bookshop/srv/i18n/messages_en.properties b/bookshop/srv/i18n/messages_en.properties new file mode 100644 index 00000000..c9c2641c --- /dev/null +++ b/bookshop/srv/i18n/messages_en.properties @@ -0,0 +1 @@ +ORDER_EXCEEDS_STOCK={0} exceeds stock for book #{1} \ No newline at end of file From 75cc2246214532bb26046b72eef0296231ee2a53 Mon Sep 17 00:00:00 2001 From: Pierre Fritsch Date: Mon, 29 Jul 2024 20:15:29 +0200 Subject: [PATCH 2/2] messages_en.properties => messages.properties --- bookshop/srv/i18n/{messages_en.properties => messages.properties} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename bookshop/srv/i18n/{messages_en.properties => messages.properties} (100%) diff --git a/bookshop/srv/i18n/messages_en.properties b/bookshop/srv/i18n/messages.properties similarity index 100% rename from bookshop/srv/i18n/messages_en.properties rename to bookshop/srv/i18n/messages.properties