I have a code like this
let item = { name: 'Roger' }
try {
return await collection.save(item)
}
catch (err) {
}
Now the collection I'm saving to has a Unique index on the field called name
. Now during the exception handling the err
object would look something like this
{
"isArangoError": true,
"response": {
"_readableState": {
"objectMode": false,
"highWaterMark": 16384,
"buffer": {
"head": null,
"tail": null,
"length": 0
},
"length": 0,
"pipes": [
],
"flowing": true,
"ended": true,
"endEmitted": true,
"reading": false,
"sync": true,
"needReadable": false,
"emittedReadable": false,
"readableListening": false,
"resumeScheduled": false,
"paused": false,
"errorEmitted": false,
"emitClose": true,
"autoDestroy": false,
"destroyed": false,
"defaultEncoding": "utf8",
"awaitDrainWriters": null,
"multiAwaitDrain": false,
"readingMore": true,
"decoder": null,
"encoding": null
},
"body": {
"code": 409,
"error": true,
"errorMessage": "unique constraint violated - in index name_is_unique of type persistent over 'name'; conflicting key: 15816187",
"errorNum": 1210
},
"arangojsHostId": 0
},
"statusCode": 409,
"errorNum": 1210,
"code": 409
}
While the error message is indeed helpful in conveying that name
should be unique, wish there is an attribute/field in the error object to grab the conflicted field name.
How to get the field name other than regex parsing from the error message?