@pbvision/firestore-orm 0.0.14 → 0.0.15
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 +30 -4
package/package.json
CHANGED
package/src/context.js
CHANGED
|
@@ -642,11 +642,18 @@ function parseFirestoreError (err) {
|
|
|
642
642
|
}
|
|
643
643
|
|
|
644
644
|
// error 6 is if you try to create a model that already exists
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
645
|
+
if (err.code === 6) {
|
|
646
|
+
// if we can't parse out the doc id, then still throw this error but the
|
|
647
|
+
// error data will require some parsing to get the doc id later (noticed
|
|
648
|
+
// that from firebase-tools 1.18.2 to 1.19.1 the format of this error
|
|
649
|
+
// changed)
|
|
650
|
+
const docInfo = parseFirestoreErrorPath(err)
|
|
651
|
+
if (!docInfo) {
|
|
652
|
+
console.warn('could not parse model already exists error: ', err)
|
|
649
653
|
}
|
|
654
|
+
return new ModelAlreadyExistsError(
|
|
655
|
+
docInfo?.collection ?? 'could not parse',
|
|
656
|
+
docInfo?.id ?? err.message)
|
|
650
657
|
}
|
|
651
658
|
}
|
|
652
659
|
}
|
|
@@ -668,5 +675,24 @@ function parseFirestoreErrorPath (err) {
|
|
|
668
675
|
return elt
|
|
669
676
|
} catch { /* no-op */ }
|
|
670
677
|
}
|
|
678
|
+
} else {
|
|
679
|
+
return parseFirestoreErrorPathAlternate(err)
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// istanbul ignore next
|
|
684
|
+
function parseFirestoreErrorPathAlternate (err) {
|
|
685
|
+
const startIdx = err.message.indexOf('path=')
|
|
686
|
+
if (startIdx === -1) {
|
|
687
|
+
return
|
|
688
|
+
}
|
|
689
|
+
const endIdx = err.message.lastIndexOf('}')
|
|
690
|
+
if (endIdx < startIdx) {
|
|
691
|
+
return
|
|
692
|
+
}
|
|
693
|
+
const path = err.message.substring(startIdx + 5, endIdx)
|
|
694
|
+
const pieces = path.split('/', 2)
|
|
695
|
+
if (pieces.length === 2) {
|
|
696
|
+
return { collection: pieces[0], id: pieces[1] }
|
|
671
697
|
}
|
|
672
698
|
}
|