mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
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:
10
frontend/projects/shared/src/classes/http-error.ts
Normal file
10
frontend/projects/shared/src/classes/http-error.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { HttpErrorResponse } from '@angular/common/http'
|
||||
|
||||
export class HttpError {
|
||||
readonly code = this.error.status
|
||||
readonly message = this.error.statusText
|
||||
readonly details = null
|
||||
readonly revision = null
|
||||
|
||||
constructor(private readonly error: HttpErrorResponse) {}
|
||||
}
|
||||
25
frontend/projects/shared/src/classes/rpc-error.ts
Normal file
25
frontend/projects/shared/src/classes/rpc-error.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { RpcErrorDetails } from '../types/rpc-error-details'
|
||||
|
||||
export class RpcError<T> {
|
||||
readonly code = this.error.code
|
||||
readonly message = this.getMessage()
|
||||
readonly revision = this.getRevision()
|
||||
|
||||
constructor(private readonly error: RpcErrorDetails<T>) {}
|
||||
|
||||
private getMessage(): string {
|
||||
if (typeof this.error.data === 'string') {
|
||||
return `${this.error.message}\n\n${this.error.data}`
|
||||
}
|
||||
|
||||
return this.error.data.details
|
||||
? `${this.error.message}\n\n${this.error.data.details}`
|
||||
: this.error.message
|
||||
}
|
||||
|
||||
private getRevision(): T | null {
|
||||
return typeof this.error.data === 'string'
|
||||
? null
|
||||
: this.error.data.revision || null
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,9 @@
|
||||
* Public API Surface of @start9labs/shared
|
||||
*/
|
||||
|
||||
export * from './classes/http-error'
|
||||
export * from './classes/rpc-error'
|
||||
|
||||
export * from './components/markdown/markdown.component'
|
||||
export * from './components/markdown/markdown.module'
|
||||
export * from './components/text-spinner/text-spinner.component.module'
|
||||
@@ -27,6 +30,7 @@ export * from './services/destroy.service'
|
||||
export * from './services/emver.service'
|
||||
export * from './services/error-toast.service'
|
||||
|
||||
export * from './types/rpc-error-details'
|
||||
export * from './types/url'
|
||||
export * from './types/workspace-config'
|
||||
|
||||
|
||||
10
frontend/projects/shared/src/types/rpc-error-details.ts
Normal file
10
frontend/projects/shared/src/types/rpc-error-details.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export interface RpcErrorDetails<T> {
|
||||
code: number
|
||||
message: string
|
||||
data?:
|
||||
| {
|
||||
details: string
|
||||
revision?: T | null
|
||||
}
|
||||
| string
|
||||
}
|
||||
@@ -14,14 +14,14 @@ export function capitalizeFirstLetter(string: string): string {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1)
|
||||
}
|
||||
|
||||
export const exists = (t: any) => {
|
||||
export function exists<T>(t: T | undefined): t is T {
|
||||
return t !== undefined
|
||||
}
|
||||
|
||||
export function debounce(delay: number = 300): MethodDecorator {
|
||||
return function (
|
||||
target: any,
|
||||
propertyKey: string,
|
||||
propertyKey: string | symbol,
|
||||
descriptor: PropertyDescriptor,
|
||||
) {
|
||||
const timeoutKey = Symbol()
|
||||
|
||||
Reference in New Issue
Block a user