Skip to content

Commit

Permalink
refactor: remove unnecessary error checking in PostgresAdapter (#7761)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaker6 authored Jan 2, 2022
1 parent 7af5de4 commit 5e363ea
Showing 1 changed file with 2 additions and 27 deletions.
29 changes: 2 additions & 27 deletions src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const PostgresRelationDoesNotExistError = '42P01';
const PostgresDuplicateRelationError = '42P07';
const PostgresDuplicateColumnError = '42701';
const PostgresMissingColumnError = '42703';
const PostgresDuplicateObjectError = '42710';
const PostgresUniqueIndexViolationError = '23505';
const logger = require('../../../logger');

Expand Down Expand Up @@ -906,15 +905,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
'CREATE TABLE IF NOT EXISTS "_SCHEMA" ( "className" varChar(120), "schema" jsonb, "isParseClass" bool, PRIMARY KEY ("className") )'
)
.catch(error => {
if (
error.code === PostgresDuplicateRelationError ||
error.code === PostgresUniqueIndexViolationError ||
error.code === PostgresDuplicateObjectError
) {
// Table already exists, must have been created by a different request. Ignore error.
} else {
throw error;
}
throw error;
});
}

Expand Down Expand Up @@ -2450,23 +2441,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
: fieldNames.map((fieldName, index) => `$${index + 3}:name`);
const qs = `CREATE INDEX IF NOT EXISTS $1:name ON $2:name (${constraintPatterns.join()})`;
await conn.none(qs, [indexNameOptions.name, className, ...fieldNames]).catch(error => {
if (
error.code === PostgresDuplicateRelationError &&
error.message.includes(indexNameOptions.name)
) {
// Index already exists. Ignore error.
} else if (
error.code === PostgresUniqueIndexViolationError &&
error.message.includes(indexNameOptions.name)
) {
// Cast the error into the proper parse error
throw new Parse.Error(
Parse.Error.DUPLICATE_VALUE,
'A duplicate value for a field with unique values was provided'
);
} else {
throw error;
}
throw error;
});
}
}
Expand Down

0 comments on commit 5e363ea

Please sign in to comment.