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