Skip to content

Commit

Permalink
fix: remove error clutter (#115)
Browse files Browse the repository at this point in the history
closes #75
  • Loading branch information
sjvans authored Sep 13, 2024
1 parent 20a27c1 commit 9e2b920
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
The format is based on [Keep a Changelog](http://keepachangelog.com/).

## Version 0.8.1 - 2024-09-12
## Version 0.8.1 - 2024-09-13

### Fixed

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

## Version 0.8.0 - 2024-05-24

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Welcome to @cap-js/audit-logging

[![REUSE status](https://api.reuse.software/badge/github.com/cap-js/audit-logging)](https://api.reuse.software/info/github.com/cap-js/audit-logging)

`@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.
Expand All @@ -19,14 +20,18 @@ cd incidents-app
npm i
```


## Setup

To enable audit logging, simply add this self-configuring plugin package to your project:

```sh
npm add @cap-js/audit-logging
```


## Annotate Personal Data

Identify entities and elements (potentially) holding personal data using `@PersonalData` annotations. Create a `db/data-privacy.cds` file and add the following:

```cds
Expand Down Expand Up @@ -69,6 +74,7 @@ Learn more about the annotations in capire:


## Test-Drive Locally

You've prepared everything to log personal data-related events. Let's see that in action.

Start the server as usual:
Expand Down Expand Up @@ -120,14 +126,17 @@ The end-to-end out-of-the-box functionality provided by this plugin requires a p
[_Learn more about custom audit logging._](https://cap.cloud.sap/docs/guides/data-privacy/audit-logging#custom-audit-logging)
## Support, Feedback, Contributing
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).
## Code of Conduct
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.
## Licensing
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).
10 changes: 7 additions & 3 deletions srv/log2restv2.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,16 @@ async function _post(url, data, options) {
const chunks = []
res.on('data', chunk => chunks.push(chunk))
res.on('end', () => {
const { statusCode, statusMessage } = res
let body = Buffer.concat(chunks).toString()
if (res.headers['content-type']?.match(/json/)) body = JSON.parse(body)
if (res.statusCode >= 400) {
const err = new Error(res.statusMessage)
err.response = res
err.body = body
// prettier-ignore
const err = new Error(`Request failed with${statusMessage ? `: ${statusCode} - ${statusMessage}` : ` status ${statusCode}`}`)
err.request = { method: options.method, url, headers: options.headers, body: data }
if (err.request.headers.authorization)
err.request.headers.authorization = err.request.headers.authorization.split(' ')[0] + ' ***'
err.response = { statusCode, statusMessage, headers: res.headers, body }
reject(err)
} else {
resolve(body)
Expand Down
2 changes: 1 addition & 1 deletion test/personal-data/crud.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const cds = require('@sap/cds')

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

// with old db, the persistent outbox adds a delay
// the persistent outbox adds a delay
const wait = require('util').promisify(setTimeout)
const POST = (...args) => _POST(...args).then(async res => (await wait(7), res))
const PATCH = (...args) => _PATCH(...args).then(async res => (await wait(7), res))
Expand Down
10 changes: 5 additions & 5 deletions test/personal-data/fiori.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ const cds = require('@sap/cds')

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

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

const _logger = require('../utils/logger')({ debug: true })
cds.log.Logger = _logger
Expand Down
4 changes: 2 additions & 2 deletions test/personal-data/handle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ const cds = require('@sap/cds')

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

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

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

Expand Down

0 comments on commit 9e2b920

Please sign in to comment.