Only throw unexpected errors from openDb

This commit is contained in:
Julia Friesel
2018-10-30 09:14:46 +01:00
parent 7cadb01b13
commit 207b5504e7
3 changed files with 17 additions and 13 deletions
+4 -7
View File
@@ -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
View File
@@ -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)