UBERF-8993: Fix handling of known errors (#7526)
Some checks failed
CI / build (push) Has been cancelled
CI / uitest (push) Has been cancelled
CI / uitest-pg (push) Has been cancelled
CI / uitest-qms (push) Has been cancelled
CI / svelte-check (push) Has been cancelled
CI / formatting (push) Has been cancelled
CI / test (push) Has been cancelled
CI / docker-build (push) Has been cancelled
CI / dist-build (push) Has been cancelled

This commit is contained in:
Andrey Sobolev 2024-12-23 17:54:09 +07:00 committed by GitHub
parent 54ff768844
commit 6a7d9e3bda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 33 additions and 6 deletions

View File

@ -131,6 +131,7 @@ export default plugin(platformId, {
BadError: '' as StatusCode,
UnknownError: '' as StatusCode<{ message: string }>,
InvalidId: '' as StatusCode<{ id: string }>,
ConnectionClosed: '' as StatusCode,
LoadingPlugin: '' as StatusCode<{ plugin: string }>,
NoLocationForPlugin: '' as StatusCode<{ plugin: Plugin }>,

View File

@ -18,7 +18,7 @@ import {
type TxResult,
type WithLookup
} from '@hcengineering/core'
import { setPlatformStatus, unknownError, type Resource } from '@hcengineering/platform'
import platform, { PlatformError, setPlatformStatus, unknownError, type Resource } from '@hcengineering/platform'
/**
* @public
@ -112,7 +112,12 @@ export class PresentationPipelineImpl implements PresentationPipeline {
return this.head !== undefined
? await this.head.findAll(_class, query, options)
: await this.client.findAll(_class, query, options)
} catch (err) {
} catch (err: any) {
if (err instanceof PlatformError) {
if (err.status.code === platform.status.ConnectionClosed) {
return toFindResult([], -1)
}
}
Analytics.handleError(err as Error)
const status = unknownError(err)
await setPlatformStatus(status)
@ -134,6 +139,11 @@ export class PresentationPipelineImpl implements PresentationPipeline {
? await this.head.findOne(_class, query, options)
: await this.client.findOne(_class, query, options)
} catch (err) {
if (err instanceof PlatformError) {
if (err.status.code === platform.status.ConnectionClosed) {
return
}
}
Analytics.handleError(err as Error)
const status = unknownError(err)
await setPlatformStatus(status)
@ -163,6 +173,11 @@ export class PresentationPipelineImpl implements PresentationPipeline {
return await this.head.tx(tx)
}
} catch (err) {
if (err instanceof PlatformError) {
if (err.status.code === platform.status.ConnectionClosed) {
return {}
}
}
Analytics.handleError(err as Error)
const status = unknownError(err)
await setPlatformStatus(status)

View File

@ -50,10 +50,11 @@ import core, {
} from '@hcengineering/core'
import platform, {
PlatformError,
Severity,
Status,
UNAUTHORIZED,
broadcastEvent,
getMetadata,
unknownError
getMetadata
} from '@hcengineering/platform'
import { HelloRequest, HelloResponse, RPCHandler, ReqId, type Response } from '@hcengineering/rpc'
@ -551,7 +552,7 @@ class Connection implements ClientConnection {
}): Promise<any> {
return this.ctx.newChild('send-request', {}).with(data.method, {}, async (ctx) => {
if (this.closed) {
throw new PlatformError(unknownError('connection closed'))
throw new PlatformError(new Status(Severity.ERROR, platform.status.ConnectionClosed, {}))
}
if (data.once === true) {

View File

@ -16,7 +16,7 @@
import { Analytics } from '@hcengineering/analytics'
import { AccountRole, concatLink, type BaseWorkspaceInfo, type Doc, type Ref } from '@hcengineering/core'
import { loginId, type LoginInfo, type OtpInfo, type Workspace, type WorkspaceLoginInfo } from '@hcengineering/login'
import {
import platform, {
OK,
PlatformError,
Severity,
@ -1058,6 +1058,10 @@ export async function restorePassword (token: string, password: string): Promise
}
async function handleStatusError (message: string, err: Status): Promise<void> {
if (err.code === platform.status.InvalidPassword || err.code === platform.status.AccountNotFound) {
// No need to send to analytics
return
}
const label = await translate(err.code, err.params, 'en')
Analytics.handleError(new Error(`${message}: ${label}`))
}

View File

@ -2637,6 +2637,12 @@ function wrap (
error: new Status(Severity.ERROR, platform.status.Unauthorized, {})
}
}
if (status.code === platform.status.InvalidPassword || status.code === platform.status.AccountNotFound) {
ctx.warn('error', { status: status.code, err: err.message })
return {
error: status
}
}
if (status.code === platform.status.InternalServerError) {
Analytics.handleError(err)
ctx.error('error', { status, err })