Skip to content

Commit

Permalink
Change request/error handling
Browse files Browse the repository at this point in the history
Fixes DE-955.
  • Loading branch information
pluma4345 committed Nov 20, 2024
1 parent 6b01762 commit f22e90f
Show file tree
Hide file tree
Showing 8 changed files with 595 additions and 256 deletions.
113 changes: 113 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,121 @@ This driver uses semantic versioning:

## [Unreleased]

### Changed

- Errors encountered before a request completes are now wrapped in a `NetworkError`

This should help making it easier to diagnose network issues and distinguish
the relevant error conditions.

The originating error can still be accessed using the `cause` property of the
`NetworkError` error.

- `HttpError` now extends the `NetworkError` type

This allows treating all non-`ArangoError` errors as one category of errors,
even when there is no server response available.

- `db.waitForPropagation` now throws a `PropagationTimeoutError` error when
invoked with a `timeout` option and the timeout duration is exceeded

The method would previously throw the most recent error encountered while
waiting for replication. The originating error can still be accessed using
the `cause` property of the `PropagationTimeoutError` error.

- `db.waitForPropagation` now respects the `timeout` option more strictly

Previously the method would only time out if the timeout duration was
exceeded after the most recent request failed. Now the timeout is
recalculated and passed on to each request, preventing it from exceeding
the specified duration.

If the propagation timed out due to an underlying request exceeding the
timeout duration, the `cause` property of the `PropagationTimeoutError`
error will be a `ResponseTimeoutError` error.

- `config.beforeRequest` and `config.afterResponse` callbacks can now return
promises

If the callback returns a promise, it will be awaited before the request
and response cycle proceeds. If either callback throws an error or returns
a promise that is rejected, that error will be thrown instead.

- `config.afterResponse` callback signature changed

The callback signature previously used the internal `ArangojsResponse` type.
The new signature uses the `Response` type of the Fetch API with an
additional `request` property to more accurately represent the actual value
it receives as the `parsedBody` property will never be present.

- `response` property on `ArangoError` is now optional

This property should always be present but this allows using the error in
situations where a response might not be available.

### Added

- Added `onError` option to `Config` (DE-955)

This option can be used to specify a callback function that will be invoked
whenever a request results in an error. Unlike `afterResponse`, this callback
will be invoked even if the request completed but returned an error status.
In this case the error will be the `HttpError` or `ArangoError` representing
the error response.

If the `onError` callback throws an error or returns a promise that is
rejected, that error will be thrown instead.

- Added `NetworkError` error type

This is the common base class for all errors (including `HttpError`) that
occur while making a request. The originating error can be accessed using the
`cause` property. The request object can be accessed using the `request`
property.

Note that `ArangoError` and the new `PropagationTimeoutError` error type
do not extend `NetworkError` but may wrap an underlying error, which can
be accessed using the `cause` property.

- Added `ResponseTimeoutError` error type

This error extends `NetworkError` and is thrown when a request deliberately
times out using the `timeout` option.

- Added `RequestAbortedError` error type

This error extends `NetworkError` and is thrown when a request is aborted
by using the `db.close` method.

- Added `FetchFailedError` error type

This error extends `NetworkError` and is thrown when a request fails because
the underlying `fetch` call fails (usually with a `TypeError`).

In Node.js the root cause of this error (e.g. a network failure) can often be
found in the `cause` property of the originating error, i.e. the `cause`
property of the `cause` property of this error.

In browsers the root cause is usually not exposed directly but can often
be diagnosed by examining the developer console or network tab.

- Added `PropagationTimeoutError` error type

This error does not extend `NetworkError` but wraps the most recent error
encountered while waiting for replication, which can be accessed using the
`cause` property. This error is only thrown when `db.waitForPropagation`
is invoked with a `timeout` option and the timeout duration is exceeded.

- Added `ProcessedResponse` type

This type replaces the previously internal `ArangojsResponse` type and
extends the native `Response` type with additional properties.

- Added optional `request` property to `ArangoError`

This property is always present if the error has a `response` property. In
normal use this should always be the case.

- Added `database` property to `Analyzer`, `ArrayCursor`, `BatchedArrayCursor`,
`Collection`, `Graph`, `Job`, `Route`, `Transaction` and `View` types (DE-935)

Expand Down
Loading

0 comments on commit f22e90f

Please sign in to comment.