Return correct error when violating unique index (#1763)

This commit is contained in:
Marco Cheung
2016-05-12 08:24:15 +08:00
committed by Drew
parent 6cfcb4ddf8
commit 19e7407f55
2 changed files with 30 additions and 1 deletions

View File

@@ -166,7 +166,14 @@ export class MongoStorageAdapter {
createObject(className, object, schemaController, parseFormatSchema) {
const mongoObject = transform.parseObjectToMongoObjectForCreate(schemaController, className, object, parseFormatSchema);
return this.adaptiveCollection(className)
.then(collection => collection.insertOne(mongoObject));
.then(collection => collection.insertOne(mongoObject))
.catch(error => {
if (error.code === 11000) { // Duplicate value
throw new Parse.Error(Parse.Error.DUPLICATE_VALUE,
'A duplicate value for a field with unique values was provided');
}
return Promise.reject(error);
});
}
// Remove all objects that match the given parse query. Parse Query should be in Parse Format.