@@ -139,21 +139,42 @@ and [the `db` object](https://www.arangodb.com/docs/stable/appendix-references-d
139
139
140
140
## Error responses
141
141
142
- If arangojs encounters an API error, it will throw an ` ArangoError ` with
143
- an ` errorNum ` property indicating the ArangoDB error code and the ` code `
144
- property indicating the HTTP status code from the response body .
142
+ If the server returns an ArangoDB error response, arangojs will throw an
143
+ ` ArangoError ` with an ` errorNum ` property indicating the ArangoDB error code
144
+ and expose the response body as the ` response ` property of the error object .
145
145
146
- For any other non-ArangoDB error responses (4xx/5xx status code), it will throw
147
- an ` HttpError ` error with the status code indicated by the ` code ` property.
146
+ For all other errors during the request/response cycle, arangojs will throw a
147
+ ` NetworkError ` or a more specific subclass thereof and expose the originating
148
+ request object as the ` request ` property of the error object.
148
149
149
- If the server response did not indicate an error but the response body could
150
- not be parsed, a regular ` SyntaxError ` may be thrown instead.
150
+ If the server responded with a non-2xx status code, this ` NetworkError ` will
151
+ be an ` HttpError ` with a ` code ` property indicating the HTTP status code of the
152
+ response and a ` response ` property containing the response object itself.
151
153
152
- In all of these cases the server response object will be exposed as the
153
- ` response ` property on the error object.
154
+ If the error is caused by an exception, the originating exception will be
155
+ available as the ` cause ` property of the error object thrown by arangojs. For
156
+ network errors, this will often be a ` TypeError ` .
154
157
155
- If the request failed at a network level or the connection was closed without
156
- receiving a response, the underlying system error will be thrown instead.
158
+ ### Node.js network errors
159
+
160
+ In Node.js, network errors caused by a ` TypeError ` will often have a ` cause `
161
+ property containing a more detailed exception.
162
+
163
+ Specifically, these are often either system errors (represented by regular
164
+ ` Error ` objects with additional properties) or errors from the ` undici ` module
165
+ Node.js uses internally for its native ` fetch ` implementation.
166
+
167
+ Node.js system error objects provide a ` code ` property containing the specific
168
+ string error code, a ` syscall ` property identifying the underlying system call
169
+ that triggered the error (e.g. ` connect ` ), as well as other helpful properties.
170
+
171
+ For more details on Node.js system errors, see the Node.js documentation of the
172
+ [ ` SystemError ` interface] ( https://nodejs.org/api/errors.html#class-systemerror )
173
+ as well as the section on
174
+ [ Node.js error codes] ( https://nodejs.org/api/errors.html#nodejs-error-codes ) .
175
+
176
+ For more details on the errors thrown by ` undici ` , see the
177
+ [ undici errors documentation] ( https://undici.nodejs.org/#/docs/api/Errors.md ) .
157
178
158
179
## Common issues
159
180
@@ -170,6 +191,15 @@ Additionally please ensure that your version of Node.js (or browser) and
170
191
ArangoDB are supported by the version of arangojs you are trying to use. See
171
192
the [ compatibility section] ( #compatibility ) for additional information.
172
193
194
+ You can install an older version of arangojs using ` npm ` or ` yarn ` :
195
+
196
+ ``` sh
197
+ # for version 8.x.x
198
+ yarn add arangojs@8
199
+ # - or -
200
+ npm install --save arangojs@8
201
+ ```
202
+
173
203
### No code intelligence when using require instead of import
174
204
175
205
If you are using ` require ` to import the ` arangojs ` module in JavaScript, the
@@ -225,7 +255,7 @@ allowing arangojs to provide more meaningful stack traces at the cost of an
225
255
impact to performance even when no error occurs.
226
256
227
257
``` diff
228
- const { Database } = require( "arangojs") ;
258
+ import { Database } from "arangojs";
229
259
230
260
const db = new Database({
231
261
url: ARANGODB_SERVER,
@@ -239,15 +269,48 @@ that do not support the `stack` property on error objects, this option will
239
269
still impact performance but not result in any additional information becoming
240
270
available.
241
271
272
+ ### Unix domain sockets
273
+
274
+ If you want to use Unix domain sockets, you need to install the ` undici ` module,
275
+ which is an optional peer dependency of arangojs.
276
+
277
+ ``` sh
278
+ npm install --save undici
279
+ ```
280
+
281
+ If the ` undici ` module is not installed and arangojs attempts to make a request
282
+ over a Unix domain socket, the request will fail with a plain ` Error ` with a
283
+ message indicating that the ` undici ` module is unavailable.
284
+
242
285
### Node.js with self-signed HTTPS certificates
243
286
244
- If you need to support self-signed HTTPS certificates in Node.js, you may have
245
- to override the global fetch agent. At the time of this writing, there is no
246
- official way to do this for the native ` fetch ` implementation in Node.js .
287
+ If you need to support self-signed HTTPS certificates in Node.js, you will need
288
+ to install the ` undici ` module, which is an optional peer dependency of
289
+ arangojs .
247
290
248
- However as Node.js uses the ` undici ` module for its ` fetch ` implementation
249
- internally, you can override the global agent by adding ` undici ` as a
250
- dependency to your project and using its ` setGlobalDispatcher ` as follows:
291
+ ``` sh
292
+ npm install --save undici
293
+ ```
294
+
295
+ You can instruct arangojs to use the ` undici ` module by setting the
296
+ ` config.agentOptions ` option:
297
+
298
+ ``` diff
299
+ import { Database } from "arangojs";
300
+
301
+ const db = new Database({
302
+ url: ARANGODB_SERVER,
303
+ + agentOptions: {
304
+ + ca: [
305
+ + fs.readFileSync(".ssl/sub.class1.server.ca.pem"),
306
+ + fs.readFileSync(".ssl/ca.pem"),
307
+ + ],
308
+ + },
309
+ });
310
+ ```
311
+
312
+ To override the global fetch agent instead, you can use the ` undici ` module's
313
+ ` setGlobalDispatcher ` method as follows:
251
314
252
315
``` js
253
316
import { Agent , setGlobalDispatcher } from " undici" ;
@@ -263,20 +326,22 @@ setGlobalDispatcher(
263
326
```
264
327
265
328
Although this is ** strongly discouraged** , it's also possible to disable
266
- HTTPS certificate validation entirely, but note this has
329
+ HTTPS certificate validation entirely this way , but note this has
267
330
** extremely dangerous** security implications:
268
331
269
- ``` js
270
- import { Agent , setGlobalDispatcher } from " undici " ;
332
+ ``` diff
333
+ import { Database } from "arangojs ";
271
334
272
- setGlobalDispatcher (
273
- new Agent ({
274
- rejectUnauthorized: false ,
275
- })
276
- );
335
+ const db = new Database({
336
+ url: ARANGODB_SERVER,
337
+ + agentOptions: {
338
+ + rejectUnauthorized: false,
339
+ + },
340
+ });
277
341
```
278
342
279
- This is a [ known limitation] ( https://github.com/orgs/nodejs/discussions/44038#discussioncomment-5701073 )
343
+ The requirement to use the ` undici ` module to override these settings is a
344
+ [ known limitation] ( https://github.com/orgs/nodejs/discussions/44038#discussioncomment-5701073 )
280
345
of Node.js at the time of this writing.
281
346
282
347
When using arangojs in the browser, self-signed HTTPS certificates need to
0 commit comments