mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-20 15:20:18 +00:00
Correct error handling (#5023)
This commit is contained in:
parent
62e3ccdc7b
commit
bc7ed968fc
@ -93,5 +93,8 @@ export function unknownStatus (message: string): Status<any> {
|
|||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export function unknownError (err: unknown): Status {
|
export function unknownError (err: unknown): Status {
|
||||||
return err instanceof PlatformError ? err.status : err instanceof Error ? unknownStatus(err.message) : ERROR
|
if (err instanceof PlatformError) return err.status
|
||||||
|
if (err instanceof Error) return unknownStatus(err.message)
|
||||||
|
if (typeof err === 'string') return unknownStatus(err)
|
||||||
|
return ERROR
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hcengineering/platform": "^0.6.9",
|
"@hcengineering/platform": "^0.6.9",
|
||||||
"@hcengineering/core": "^0.6.28",
|
"@hcengineering/core": "^0.6.28",
|
||||||
|
"@hcengineering/analytics": "^0.6.0",
|
||||||
"@hcengineering/query": "^0.6.8",
|
"@hcengineering/query": "^0.6.8",
|
||||||
"@hcengineering/ui": "^0.6.11",
|
"@hcengineering/ui": "^0.6.11",
|
||||||
"@hcengineering/view": "^0.6.9",
|
"@hcengineering/view": "^0.6.9",
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { Analytics } from '@hcengineering/analytics'
|
||||||
import {
|
import {
|
||||||
toFindResult,
|
toFindResult,
|
||||||
type Class,
|
type Class,
|
||||||
@ -18,7 +19,7 @@ import {
|
|||||||
type TxResult,
|
type TxResult,
|
||||||
type WithLookup
|
type WithLookup
|
||||||
} from '@hcengineering/core'
|
} from '@hcengineering/core'
|
||||||
import { type Resource } from '@hcengineering/platform'
|
import { setPlatformStatus, unknownError, type Resource } from '@hcengineering/platform'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
@ -112,9 +113,16 @@ export class PresentationPipelineImpl implements PresentationPipeline {
|
|||||||
query: DocumentQuery<T>,
|
query: DocumentQuery<T>,
|
||||||
options?: FindOptions<T>
|
options?: FindOptions<T>
|
||||||
): Promise<FindResult<T>> {
|
): Promise<FindResult<T>> {
|
||||||
return this.head !== undefined
|
try {
|
||||||
? await this.head.findAll(_class, query, options)
|
return this.head !== undefined
|
||||||
: await this.client.findAll(_class, query, options)
|
? await this.head.findAll(_class, query, options)
|
||||||
|
: await this.client.findAll(_class, query, options)
|
||||||
|
} catch (err) {
|
||||||
|
Analytics.handleError(err as Error)
|
||||||
|
const status = unknownError(err)
|
||||||
|
await setPlatformStatus(status)
|
||||||
|
return toFindResult([], -1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async searchFulltext (query: SearchQuery, options: SearchOptions): Promise<SearchResult> {
|
async searchFulltext (query: SearchQuery, options: SearchOptions): Promise<SearchResult> {
|
||||||
@ -126,9 +134,15 @@ export class PresentationPipelineImpl implements PresentationPipeline {
|
|||||||
query: DocumentQuery<T>,
|
query: DocumentQuery<T>,
|
||||||
options?: FindOptions<T>
|
options?: FindOptions<T>
|
||||||
): Promise<WithLookup<T> | undefined> {
|
): Promise<WithLookup<T> | undefined> {
|
||||||
return this.head !== undefined
|
try {
|
||||||
? await this.head.findOne(_class, query, options)
|
return this.head !== undefined
|
||||||
: await this.client.findOne(_class, query, options)
|
? await this.head.findOne(_class, query, options)
|
||||||
|
: await this.client.findOne(_class, query, options)
|
||||||
|
} catch (err) {
|
||||||
|
Analytics.handleError(err as Error)
|
||||||
|
const status = unknownError(err)
|
||||||
|
await setPlatformStatus(status)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async subscribe<T extends Doc>(
|
async subscribe<T extends Doc>(
|
||||||
@ -147,15 +161,26 @@ export class PresentationPipelineImpl implements PresentationPipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async tx (tx: Tx): Promise<TxResult> {
|
async tx (tx: Tx): Promise<TxResult> {
|
||||||
if (this.head === undefined) {
|
try {
|
||||||
return await this.client.tx(tx)
|
if (this.head === undefined) {
|
||||||
} else {
|
return await this.client.tx(tx)
|
||||||
return await this.head.tx(tx)
|
} else {
|
||||||
|
return await this.head.tx(tx)
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
Analytics.handleError(err as Error)
|
||||||
|
const status = unknownError(err)
|
||||||
|
await setPlatformStatus(status)
|
||||||
|
return {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async close (): Promise<void> {
|
async close (): Promise<void> {
|
||||||
await this.head?.close()
|
if (this.head !== undefined) {
|
||||||
|
await this.head.close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await this.client.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +198,11 @@ export abstract class BasePresentationMiddleware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async provideClose (): Promise<void> {
|
async provideClose (): Promise<void> {
|
||||||
await this.next?.close()
|
if (this.next !== undefined) {
|
||||||
|
await this.next.close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await this.client.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll<T extends Doc>(
|
async findAll<T extends Doc>(
|
||||||
|
@ -25,10 +25,11 @@
|
|||||||
location,
|
location,
|
||||||
setMetadataLocalStorage
|
setMetadataLocalStorage
|
||||||
} from '@hcengineering/ui'
|
} from '@hcengineering/ui'
|
||||||
import { connect, versionError } from '../connect'
|
import { connect, disconnect, versionError } from '../connect'
|
||||||
|
|
||||||
import { workbenchId } from '@hcengineering/workbench'
|
import { workbenchId } from '@hcengineering/workbench'
|
||||||
import workbench from '../plugin'
|
import workbench from '../plugin'
|
||||||
|
import { onDestroy } from 'svelte'
|
||||||
|
|
||||||
const isNeedUpgrade = window.location.host === ''
|
const isNeedUpgrade = window.location.host === ''
|
||||||
|
|
||||||
@ -38,6 +39,8 @@
|
|||||||
setMetadataLocalStorage(workbench.metadata.MobileAllowed, true)
|
setMetadataLocalStorage(workbench.metadata.MobileAllowed, true)
|
||||||
mobileAllowed = true
|
mobileAllowed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onDestroy(disconnect)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if $location.path[0] === workbenchId || $location.path[0] === workbench.component.WorkbenchApp}
|
{#if $location.path[0] === workbenchId || $location.path[0] === workbench.component.WorkbenchApp}
|
||||||
|
@ -32,6 +32,14 @@ addEventListener(client.event.NetworkRequests, async (event: string, val: number
|
|||||||
networkStatus.set(val)
|
networkStatus.set(val)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export async function disconnect (): Promise<void> {
|
||||||
|
if (_client !== undefined) {
|
||||||
|
await _client.close()
|
||||||
|
_client = undefined
|
||||||
|
_clientSet = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function connect (title: string): Promise<Client | undefined> {
|
export async function connect (title: string): Promise<Client | undefined> {
|
||||||
const loc = getCurrentLocation()
|
const loc = getCurrentLocation()
|
||||||
const ws = loc.path[1]
|
const ws = loc.path[1]
|
||||||
|
Loading…
Reference in New Issue
Block a user