Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit 79eb8ca

Browse files
committed
Localize the custom error message
as documented in: https://cap.cloud.sap/docs/node.js/app-services#custom-errors
1 parent 1fde0c9 commit 79eb8ca

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

bookshop/srv/cat-service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class CatalogService extends cds.ApplicationService { init(){
99
const {book,quantity} = req.data
1010
if (quantity < 1) return req.reject (400,`quantity has to be 1 or more`)
1111
let {stock} = await SELECT `stock` .from (Books,book)
12-
if (quantity > stock) return req.reject (409,`${quantity} exceeds stock for book #${book}`)
12+
if (quantity > stock) return req.reject (409, "ORDER_EXCEEDS_STOCK", [quantity, book])
1313
await UPDATE (Books,book) .with ({ stock: stock -= quantity })
1414
await this.emit ('OrderedBook', { book, quantity, buyer:req.user.id })
1515
return { stock }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ORDER_EXCEEDS_STOCK={0} exceeds stock for book #{1}

0 commit comments

Comments
 (0)