Skip to content

Commit

Permalink
Localize the custom error message
Browse files Browse the repository at this point in the history
as documented in:
https://cap.cloud.sap/docs/node.js/app-services#custom-errors

Signed-off-by: Pierre Fritsch <PierreFritsch@users.noreply.github.com>
  • Loading branch information
PierreFritsch committed Dec 10, 2021
1 parent 1fde0c9 commit 085a63a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bookshop/srv/cat-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
1 change: 1 addition & 0 deletions bookshop/srv/i18n/messages_en.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ORDER_EXCEEDS_STOCK={0} exceeds stock for book #{1}

0 comments on commit 085a63a

Please sign in to comment.