Only throw unexpected errors from openDb
This commit is contained in:
@@ -24,22 +24,19 @@ export default class PasswordPrompt extends Component {
|
||||
}
|
||||
|
||||
async tryToOpenDb() {
|
||||
try {
|
||||
await openDb({ persistConnection: true })
|
||||
} catch (err) {
|
||||
const connected = await openDb({ persistConnection: true })
|
||||
if (!connected) {
|
||||
this.setState({ showPasswordPrompt: true })
|
||||
await saveEncryptionFlag(true)
|
||||
return
|
||||
}
|
||||
|
||||
await saveEncryptionFlag(false)
|
||||
this.props.showApp()
|
||||
}
|
||||
|
||||
passHashToDb = async hash => {
|
||||
try {
|
||||
await openDb({ hash, persistConnection: true })
|
||||
} catch (err) {
|
||||
const connected = await openDb({ hash, persistConnection: true })
|
||||
if (!connected) {
|
||||
Alert.alert(
|
||||
shared.incorrectPassword,
|
||||
shared.incorrectPasswordMessage,
|
||||
|
||||
@@ -3,10 +3,8 @@ import { openDb } from '../../../db'
|
||||
import { shared } from '../../labels'
|
||||
|
||||
export default async function checkPassword({hash, onCancel, onTryAgain }) {
|
||||
try {
|
||||
await openDb({ hash, persistConnection: false })
|
||||
return true
|
||||
} catch (err) {
|
||||
const connected = await openDb({ hash, persistConnection: false })
|
||||
if (!connected) {
|
||||
Alert.alert(
|
||||
shared.incorrectPassword,
|
||||
shared.incorrectPasswordMessage,
|
||||
|
||||
+11
-2
@@ -29,16 +29,25 @@ export async function openDb ({ hash, persistConnection }) {
|
||||
|
||||
// open the Realm with the latest schema
|
||||
realmConfig.schema = schemas[schemas.length - 1]
|
||||
const connection = await Realm.open(Object.assign(
|
||||
let connection
|
||||
try {
|
||||
connection = await Realm.open(Object.assign(
|
||||
realmConfig,
|
||||
schemas[schemas.length - 1]
|
||||
))
|
||||
} catch(err) {
|
||||
if (!err.toString().includes('decrypt')) throw err
|
||||
return false
|
||||
}
|
||||
|
||||
if (persistConnection) db = connection
|
||||
if (persistConnection) {
|
||||
db = connection
|
||||
const cycle = cycleModule()
|
||||
isMensesStart = cycle.isMensesStart
|
||||
getMensesDaysRightAfter = cycle.getMensesDaysRightAfter
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
export function getBleedingDaysSortedByDate() {
|
||||
return db.objects('CycleDay').filtered('bleeding != null').sorted('date', true)
|
||||
|
||||
Reference in New Issue
Block a user