Skip to content

Commit 9e2b920

Browse files
authored
fix: remove error clutter (#115)
closes #75
1 parent 20a27c1 commit 9e2b920

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55
The format is based on [Keep a Changelog](http://keepachangelog.com/).
66

7-
## Version 0.8.1 - 2024-09-12
7+
## Version 0.8.1 - 2024-09-13
88

99
### Fixed
1010

1111
- Support for @sap/cds^8.2
12+
- Reduce clutter in error raised for outbound requests
1213

1314
## Version 0.8.0 - 2024-05-24
1415

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Welcome to @cap-js/audit-logging
2+
23
[![REUSE status](https://api.reuse.software/badge/github.com/cap-js/audit-logging)](https://api.reuse.software/info/github.com/cap-js/audit-logging)
34

45
`@cap-js/audit-logging` is a CDS plugin providing integration to the SAP Audit Log service as well as out-of-the-box personal data-related audit logging based on annotations.
@@ -19,14 +20,18 @@ cd incidents-app
1920
npm i
2021
```
2122

23+
2224
## Setup
25+
2326
To enable audit logging, simply add this self-configuring plugin package to your project:
2427

2528
```sh
2629
npm add @cap-js/audit-logging
2730
```
2831

32+
2933
## Annotate Personal Data
34+
3035
Identify entities and elements (potentially) holding personal data using `@PersonalData` annotations. Create a `db/data-privacy.cds` file and add the following:
3136

3237
```cds
@@ -69,6 +74,7 @@ Learn more about the annotations in capire:
6974

7075

7176
## Test-Drive Locally
77+
7278
You've prepared everything to log personal data-related events. Let's see that in action.
7379

7480
Start the server as usual:
@@ -120,14 +126,17 @@ The end-to-end out-of-the-box functionality provided by this plugin requires a p
120126
121127
[_Learn more about custom audit logging._](https://cap.cloud.sap/docs/guides/data-privacy/audit-logging#custom-audit-logging)
122128
129+
123130
## Support, Feedback, Contributing
124131
125132
This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/cap-js/audit-logging/issues). Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our [Contribution Guidelines](CONTRIBUTING.md).
126133
134+
127135
## Code of Conduct
128136
129137
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its [Code of Conduct](CODE_OF_CONDUCT.md) at all times.
130138
139+
131140
## Licensing
132141
133142
Copyright 2023 SAP SE or an SAP affiliate company and contributors. Please see our [LICENSE](LICENSE) for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available [via the REUSE tool](https://api.reuse.software/info/github.com/cap-js/audit-logging).

srv/log2restv2.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,16 @@ async function _post(url, data, options) {
154154
const chunks = []
155155
res.on('data', chunk => chunks.push(chunk))
156156
res.on('end', () => {
157+
const { statusCode, statusMessage } = res
157158
let body = Buffer.concat(chunks).toString()
158159
if (res.headers['content-type']?.match(/json/)) body = JSON.parse(body)
159160
if (res.statusCode >= 400) {
160-
const err = new Error(res.statusMessage)
161-
err.response = res
162-
err.body = body
161+
// prettier-ignore
162+
const err = new Error(`Request failed with${statusMessage ? `: ${statusCode} - ${statusMessage}` : ` status ${statusCode}`}`)
163+
err.request = { method: options.method, url, headers: options.headers, body: data }
164+
if (err.request.headers.authorization)
165+
err.request.headers.authorization = err.request.headers.authorization.split(' ')[0] + ' ***'
166+
err.response = { statusCode, statusMessage, headers: res.headers, body }
163167
reject(err)
164168
} else {
165169
resolve(body)

test/personal-data/crud.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const cds = require('@sap/cds')
22

33
const { POST: _POST, PATCH: _PATCH, GET: _GET, DELETE: _DELETE, data } = cds.test().in(__dirname)
44

5-
// with old db, the persistent outbox adds a delay
5+
// the persistent outbox adds a delay
66
const wait = require('util').promisify(setTimeout)
77
const POST = (...args) => _POST(...args).then(async res => (await wait(7), res))
88
const PATCH = (...args) => _PATCH(...args).then(async res => (await wait(7), res))

test/personal-data/fiori.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ const cds = require('@sap/cds')
22

33
const { POST: _POST, PATCH: _PATCH, GET: _GET, DELETE: _DELETE, data } = cds.test().in(__dirname)
44

5-
// with old db, the persistent outbox adds a delay
5+
// the persistent outbox adds a delay
66
const wait = require('util').promisify(setTimeout)
7-
const POST = (...args) => _POST(...args).then(async res => (await wait(7), res))
8-
const PATCH = (...args) => _PATCH(...args).then(async res => (await wait(7), res))
9-
const GET = (...args) => _GET(...args).then(async res => (await wait(7), res))
10-
const DELETE = (...args) => _DELETE(...args).then(async res => (await wait(7), res))
7+
const POST = (...args) => _POST(...args).then(async res => (await wait(42), res))
8+
const PATCH = (...args) => _PATCH(...args).then(async res => (await wait(42), res))
9+
const GET = (...args) => _GET(...args).then(async res => (await wait(42), res))
10+
const DELETE = (...args) => _DELETE(...args).then(async res => (await wait(42), res))
1111

1212
const _logger = require('../utils/logger')({ debug: true })
1313
cds.log.Logger = _logger

test/personal-data/handle.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ const cds = require('@sap/cds')
22

33
let { GET: _GET } = cds.test().in(__dirname)
44

5-
// with old db, the persistent outbox adds a delay
5+
// the persistent outbox adds a delay
66
const wait = require('util').promisify(setTimeout)
7-
const GET = (...args) => _GET(...args).then(async res => (await wait(7), res))
7+
const GET = (...args) => _GET(...args).then(async res => (await wait(42), res))
88

99
cds.env.requires['audit-log'].handle = ['WRITE']
1010

0 commit comments

Comments
 (0)