Abort
Abort( message )
Description
The Abort
function terminates the current transaction and augments
the returned error with the associated message. Any modifications to
data or schema in the aborted transaction are ignored, even if this
modification took place before the abort function was executed.
Examples
The query below is a single transaction with three statements. The first
statement creates a collection, the second statement adds an document to
the collection, and the third statement aborts the transaction. Due to
the transaction being terminated by the Abort
call, neither the
creation of the collection nor the addition of the document is present
in the database.
client.query([
q.CreateCollection({ name: 'cars' }),
q.Now(),
q.Abort('Reset Transaction'),
])
.then((ret) => console.log(ret))
.catch((err) => console.log('Error:', err))
Error: { [BadRequest: transaction aborted]
name: 'BadRequest',
message: 'transaction aborted',
requestResult:
RequestResult {
client:
Client {
_baseUrl: 'http://localhost:8443',
_timeout: 60000,
_secret: 'secret',
_observer: null,
_lastSeen: 1574192104670000,
_keepAliveEnabledAgent: [Agent] },
method: 'POST',
path: '',
query: null,
requestRaw:
'[{"create_collection":{"object":{"name":"cars"}}},{"now":null},{"abort":"Reset Transaction"}]',
requestContent: Expr { raw: [Array] },
responseRaw:
'{"errors":[{"position":[2],"code":"transaction aborted","description":"Reset Transaction"}]}',
responseContent: { errors: [Array] },
statusCode: 400,
responseHeaders:
{ connection: 'keep-alive',
'content-length': '92',
'content-type': 'application/json;charset=utf-8',
'x-faunadb-build': '2.10.0.nightly20191113-157960d',
'x-query-bytes-in': '93',
'x-query-bytes-out': '92',
'x-query-time': '13',
'x-read-ops': '0',
'x-storage-bytes-read': '0',
'x-storage-bytes-write': '0',
'x-txn-retries': '0',
'x-txn-time': '1574192104670000',
'x-write-ops': '1' },
startTime: 1574192104611,
endTime: 1574192104654 } }
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!