@pbvision/firestore-orm 0.0.23 → 0.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/context.js +17 -0
- package/src/errors.js +17 -0
package/package.json
CHANGED
package/src/context.js
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
WriteAttemptedInReadOnlyTxError,
|
|
15
15
|
ModelTrackedTwiceError,
|
|
16
16
|
ModelAlreadyExistsError,
|
|
17
|
+
TransactionExpiredError,
|
|
17
18
|
TransactionLockTimeoutError
|
|
18
19
|
} from './errors.js'
|
|
19
20
|
import { Key } from './key.js'
|
|
@@ -644,6 +645,22 @@ function parseFirestoreError (err) {
|
|
|
644
645
|
return new TransactionLockTimeoutError(err.message, err)
|
|
645
646
|
}
|
|
646
647
|
|
|
648
|
+
// error 3 is INVALID_ARGUMENT, which mostly means the caller got something
|
|
649
|
+
// wrong and must NOT be retried (bad field value, malformed query). The one
|
|
650
|
+
// exception is "The referenced transaction has expired or is no longer
|
|
651
|
+
// valid": the transaction outlived Firestore's limit before this call
|
|
652
|
+
// reached the server, which happens when the client library's own retries
|
|
653
|
+
// push a slow call past the window. That says nothing about the work being
|
|
654
|
+
// wrong, only that this attempt ran out of time, so a fresh transaction is
|
|
655
|
+
// expected to succeed. Left unclassified it was non-retryable, so a
|
|
656
|
+
// transient slowdown surfaced to callers as a hard failure. Match on the
|
|
657
|
+
// message, never on the code alone, so genuine INVALID_ARGUMENT bugs still
|
|
658
|
+
// fail fast.
|
|
659
|
+
if (err.code === 3 &&
|
|
660
|
+
/transaction has expired or is no longer valid/i.test(err.message)) {
|
|
661
|
+
return new TransactionExpiredError(err.message, err)
|
|
662
|
+
}
|
|
663
|
+
|
|
647
664
|
// error 6 is if you try to create a model that already exists
|
|
648
665
|
if (err.code === 6) {
|
|
649
666
|
// if we can't parse out the doc id, then still throw this error but the
|
package/src/errors.js
CHANGED
|
@@ -70,6 +70,23 @@ export class TransactionLockTimeoutError extends TransactionFailedError {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Thrown when Firestore rejects an operation because the transaction it names
|
|
75
|
+
* is no longer valid, i.e. the transaction outlived Firestore's limit before
|
|
76
|
+
* this call reached the server. Like a lock timeout this says nothing about the
|
|
77
|
+
* work being wrong, only that this attempt ran out of time, so a fresh attempt
|
|
78
|
+
* is expected to succeed and it is retryable.
|
|
79
|
+
*
|
|
80
|
+
* @memberof Errors
|
|
81
|
+
*/
|
|
82
|
+
export class TransactionExpiredError extends TransactionFailedError {
|
|
83
|
+
constructor (reason, original) {
|
|
84
|
+
super(reason, original)
|
|
85
|
+
this.name = this.constructor.name
|
|
86
|
+
this.retryable = true
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
73
90
|
/**
|
|
74
91
|
* Thrown when there's some error with a particular model.
|
|
75
92
|
* @memberof Errors
|