Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
## [Unreleased]

### Added
- Added `Request.messages`, `Request.errors` and `Request.results`
### Changed
### Deprecated
### Removed
Expand Down
7 changes: 7 additions & 0 deletions apis/events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Definition, LinkedCSN } from './linked'
import { Query } from './cqn'
import { ref } from './cqn'
import * as express from 'express'
import { levels } from './log'


/**
Expand Down Expand Up @@ -54,6 +55,12 @@ export class Request<
P extends Record<string, any>[] = Record<string, any>[]
> extends Event<D> {

messages: {message: string, numericSeverity: levels}[]

errors: {message: string, stack: string}[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what should be visible in types. There are further properties like numericSeverity, code, target.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got these values from experimenting with a bookshop project.
Screenshot 2025-10-21 at 10 36 27
Screenshot 2025-10-21 at 10 37 10

I'll gladly add any properties that should be available (this also showcases why me experimentally determining them is vastly inferior to a runtime expert providing them with confidence 😕)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on what you provide into req.error() as parameters. Try out req.error(code, message, target). For example req.error (400, 'Invalid input', 'some_field').

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I have added the fields accordingly, thanks for pointing that out!


results: D[]

params: P

method: string
Expand Down
10 changes: 10 additions & 0 deletions test/typescript/apis/project/cds-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ srv.before('*', async req => {
req.error(1, 'msg')
req.notify(1, 'msg', 'target', ['key', 2])
req.warn(1, 'msg', 'target', [])
req.messages.at(0)?.message
req.messages.at(0)?.numericSeverity
req.results.at(0)
req.errors.at(0)?.stack
req.errors.at(0)?.message
const thing: number | undefined = 42 as number | undefined
// @ts-expect-error possibly undefined - goes away after req.reject
thing.toExponential()
Expand All @@ -213,6 +218,11 @@ srv.after('*', (results, req) => {
srv.after('UPDATE', Books, (results, req) => {
req.data
results[0]
req.results.at(0) // any, as Books is from cds.entities
})
srv.after('UPDATE', Foos, (results, req) => {
req.data
req.results.at(0)?.ref // Foo, as Foos is a cds-typer dummy
})

srv.on("action1", req => {
Expand Down
Loading