refactor: isolate network toast and login redirect to separate services (#1412)

* refactor: isolate network toast and login redirect to separate services

* chore: remove accidentally committed sketch of a service

* chore: tidying things up

* feat: add `GlobalModule` encapsulating all global subscription services

* remove angular build cache when building deps

* chore: fix more issues found while testing

* chore: fix issues reported by testing

* chore: fix template error

* chore: fix server-info

* chore: fix server-info

* fix: switch to Observable to fix race conditions

* fix embassy name display on load

* update patchdb

* clean up patch data watch

Co-authored-by: Lucy Cifferello <12953208+elvece@users.noreply.github.com>
This commit is contained in:
Alex Inkin
2022-05-27 01:56:47 +03:00
committed by GitHub
parent 4829637b46
commit 4f3223d3ad
88 changed files with 1379 additions and 1079 deletions

View File

@@ -29,7 +29,7 @@ export class AppComponent {
this.stateService.isMigrating = false
await this.navCtrl.navigateForward(`/recover`)
}
} catch (e) {
} catch (e: any) {
this.errorToastService.present(e)
}
}

View File

@@ -73,7 +73,7 @@ export class EmbassyPage {
})
await alert.present()
}
} catch (e) {
} catch (e: any) {
this.errorToastService.present(e)
} finally {
this.loading = false
@@ -141,7 +141,7 @@ export class EmbassyPage {
} else {
await this.navCtrl.navigateForward(`/success`)
}
} catch (e) {
} catch (e: any) {
this.errorToastService.present({
message: `${e.message}\n\nRestart Embassy to try again.`,
})

View File

@@ -119,7 +119,7 @@ export class RecoverPage {
await alert.present()
this.hasShownGuidAlert = true
}
} catch (e) {
} catch (e: any) {
this.errorToastService.present(e)
} finally {
this.loading = false
@@ -205,7 +205,7 @@ export class RecoverPage {
try {
await this.stateService.importDrive(guid)
await this.navCtrl.navigateForward(`/success`)
} catch (e) {
} catch (e: any) {
this.errorToastService.present(e)
} finally {
loader.dismiss()

View File

@@ -30,7 +30,7 @@ export class SuccessPage {
encodeURIComponent(this.stateService.cert),
)
this.download()
} catch (e) {
} catch (e: any) {
await this.errCtrl.present(e)
}
}

View File

@@ -8,6 +8,7 @@ import {
import { Observable } from 'rxjs'
import * as aesjs from 'aes-js'
import * as pbkdf2 from 'pbkdf2'
import { HttpError, RpcError } from '@start9labs/shared'
@Injectable({
providedIn: 'root',
@@ -80,7 +81,7 @@ export class HttpService {
.then(res => JSON.parse(res))
.catch(e => {
if (!e.status && !e.statusText) {
throw new EncryptionError(e)
throw new EncryptionError()
} else {
throw new HttpError(e)
}
@@ -120,34 +121,10 @@ export class HttpService {
}
}
function RpcError(e: RPCError['error']): void {
const { code, message, data } = e
this.code = code
if (typeof data === 'string') {
this.message = `${message}\n\n${data}`
} else {
if (data.details) {
this.message = `${message}\n\n${data.details}`
} else {
this.message = message
}
}
}
function HttpError(e: HttpErrorResponse): void {
const { status, statusText } = e
this.code = status
this.message = statusText
this.details = null
}
function EncryptionError(e: HttpErrorResponse): void {
this.code = null
this.message = 'Invalid Key'
this.details = null
class EncryptionError {
readonly code = null
readonly message = 'Invalid Key'
readonly details = null
}
function isRpcError<Error, Result>(
@@ -205,10 +182,6 @@ export interface RPCError extends RPCBase {
export type RPCResponse<T> = RPCSuccess<T> | RPCError
type HttpError = HttpErrorResponse & {
error: { code: string; message: string }
}
export interface HttpOptions {
method: Method
url: string

View File

@@ -49,7 +49,7 @@ export class StateService {
let progress
try {
progress = await this.apiService.getRecoveryStatus()
} catch (e) {
} catch (e: any) {
this.errorToastService.present({
message: `${e.message}\n\nRestart Embassy to try again.`,
})