Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
This commit is contained in:
Denis Bykhov 2022-01-04 15:03:41 +06:00 committed by GitHub
parent 2a98f3c176
commit b2f5c6708b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 8 deletions

View File

@ -12004,7 +12004,7 @@ packages:
dev: false
file:projects/pod-account.tgz:
resolution: {integrity: sha512-1KP9YR2TMC9Zksf2G15aecCY4pIDpGaddPQ2BGtfkE2P/4XG6gYl2Mnf8GRr1c3r2IWJozLYw39MhpkXI9zCHQ==, tarball: file:projects/pod-account.tgz}
resolution: {integrity: sha512-LqJ4mBkjSWhBA9OiiMUgLeoUF9IniLh1xr/G3iXRHSm8Li6OssMSTZ733CAoWVNPchAMn5xBibLV5Mi6syer9w==, tarball: file:projects/pod-account.tgz}
name: '@rush-temp/pod-account'
version: 0.0.0
dependencies:
@ -12029,8 +12029,11 @@ packages:
koa-router: 10.1.1
mongodb: 4.2.2
prettier: 2.5.1
ts-node: 10.4.0_5d12c2add188ff0e728b4ade3dacd39b
typescript: 4.5.4
transitivePeerDependencies:
- '@swc/core'
- '@swc/wasm'
- supports-color
dev: false

View File

@ -2,6 +2,11 @@
"status": {
"LoadingPlugin": "Loading plugin '<b>'{plugin}'</b>'...",
"UnknownError": "Unknown error: {message}",
"InvalidId": "Invalid Id: {id}"
"InvalidId": "Invalid Id: {id}",
"BadRequest": "Bad request",
"Forbidden": "Forbidden",
"Unauthorized": "Unauthorized",
"UnknownMethod": "Unknown method: {method}",
"InternalServerError": "Internal server error"
}
}

View File

@ -138,6 +138,7 @@ export default plugin(platformId, {
BadRequest: '' as StatusCode,
Forbidden: '' as StatusCode,
Unauthorized: '' as StatusCode,
UnknownMethod: '' as StatusCode<{ method: string }>
UnknownMethod: '' as StatusCode<{ method: string }>,
InternalServerError: '' as StatusCode
}
})

View File

@ -14,7 +14,7 @@
// limitations under the License.
//
import { getMetadata, Metadata, Plugin, Request, Response, StatusCode, PlatformError, plugin, Severity, Status, unknownStatus } from '@anticrm/platform'
import platform, { getMetadata, Metadata, Plugin, Request, Response, PlatformError, plugin, Severity, Status, StatusCode } from '@anticrm/platform'
import { pbkdf2Sync, randomBytes } from 'crypto'
import { encode } from 'jwt-simple'
import { Binary, Db, ObjectId } from 'mongodb'
@ -45,8 +45,7 @@ const accountPlugin = plugin(accountId, {
WorkspaceNotFound: '' as StatusCode<{workspace: string}>,
InvalidPassword: '' as StatusCode<{account: string}>,
AccountAlreadyExists: '' as StatusCode<{account: string}>,
WorkspaceAlreadyExists: '' as StatusCode<{workspace: string}>,
Forbidden: '' as StatusCode
WorkspaceAlreadyExists: '' as StatusCode<{workspace: string}>
}
})
@ -170,7 +169,7 @@ export async function login (db: Db, email: string, password: string, workspace:
}
}
throw new PlatformError(new Status(Severity.ERROR, accountPlugin.status.Forbidden, {}))
throw new PlatformError(new Status(Severity.ERROR, platform.status.Forbidden, {}))
}
/**
@ -304,7 +303,7 @@ function wrap (f: (db: Db, ...args: any[]) => Promise<any>) {
return async function (db: Db, request: Request<any[]>): Promise<Response<any>> {
return await f(db, ...request.params)
.then((result) => ({ id: request.id, result }))
.catch((err) => ({ error: unknownStatus(err) }))
.catch((err) => ({ error: err instanceof PlatformError ? new Status(Severity.ERROR, platform.status.Forbidden, {}) : new Status(Severity.ERROR, platform.status.InternalServerError, {}) }))
}
}