fix(runtime): JavaScript Records API error handling (#32)

This commit is contained in:
Eric Tuvesson
2024-06-13 22:24:34 +02:00
committed by Richard Osborne
parent c66ce32449
commit af81e1304e

View File

@@ -108,6 +108,7 @@ function createRecordsAPI(modelScope) {
},
async fetch(objectOrId, options) {
if (typeof objectOrId === 'undefined') return Promise.reject(new Error("'objectOrId' is undefined."));
if (typeof objectOrId !== 'string') objectOrId = objectOrId.getId();
const className = (options ? options.className : undefined) || (modelScope || Model).get(objectOrId)._class;
@@ -130,6 +131,7 @@ function createRecordsAPI(modelScope) {
},
async increment(objectOrId, properties, options) {
if (typeof objectOrId === 'undefined') return Promise.reject(new Error("'objectOrId' is undefined."));
if (typeof objectOrId !== 'string') objectOrId = objectOrId.getId();
const className = (options ? options.className : undefined) || (modelScope || Model).get(objectOrId)._class;
@@ -153,6 +155,7 @@ function createRecordsAPI(modelScope) {
},
async save(objectOrId, properties, options) {
if (typeof objectOrId === 'undefined') return Promise.reject(new Error("'objectOrId' is undefined."));
if (typeof objectOrId !== 'string') objectOrId = objectOrId.getId();
const className = (options ? options.className : undefined) || (modelScope || Model).get(objectOrId)._class;
@@ -202,6 +205,7 @@ function createRecordsAPI(modelScope) {
},
async delete(objectOrId, options) {
if (typeof objectOrId === 'undefined') return Promise.reject(new Error("'objectOrId' is undefined."));
if (typeof objectOrId !== 'string') objectOrId = objectOrId.getId();
const className = (options ? options.className : undefined) || (modelScope || Model).get(objectOrId)._class;
@@ -270,7 +274,7 @@ function createRecordsAPI(modelScope) {
resolve();
},
error: (err) => {
reject(Error(rr || 'Failed to add relation.'));
reject(Error(err || 'Failed to add relation.'));
}
});
});