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, BadError: '' as StatusCode,
UnknownError: '' as StatusCode<{ message: string }>, UnknownError: '' as StatusCode<{ message: string }>,
InvalidId: '' as StatusCode<{ id: string }>, InvalidId: '' as StatusCode<{ id: string }>,
ConnectionClosed: '' as StatusCode,
LoadingPlugin: '' as StatusCode<{ plugin: string }>, LoadingPlugin: '' as StatusCode<{ plugin: string }>,
NoLocationForPlugin: '' as StatusCode<{ plugin: Plugin }>, NoLocationForPlugin: '' as StatusCode<{ plugin: Plugin }>,

View File

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

View File

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

View File

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

View File

@ -2637,6 +2637,12 @@ function wrap (
error: new Status(Severity.ERROR, platform.status.Unauthorized, {}) 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) { if (status.code === platform.status.InternalServerError) {
Analytics.handleError(err) Analytics.handleError(err)
ctx.error('error', { status, err }) ctx.error('error', { status, err })