TSK-568: User-friendly message on join for expired links (#2752)

Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
This commit is contained in:
Vyacheslav Tumanov 2023-03-16 18:20:49 +05:00 committed by GitHub
parent ea492902f1
commit 2401f0e6bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 2 deletions

View File

@ -5,6 +5,7 @@
"InvalidId": "Invalid Id: {id}",
"BadRequest": "Bad request",
"Forbidden": "Forbidden",
"ExpiredLink": "This invite link is expired",
"Unauthorized": "Unauthorized",
"UnknownMethod": "Unknown method: {method}",
"InternalServerError": "Internal server error"

View File

@ -5,8 +5,9 @@
"InvalidId": "Некорректный Id: {id}",
"BadRequest": "Некорректный запрос",
"Forbidden": "Запрещено",
"ExpiredLink": "Ссылка истекла",
"Unauthorized": "Неавторизован",
"UnknownMethod": "Неизвестный метод: {method}",
"InternalServerError": "Внутренняя ошибка сервеа"
"InternalServerError": "Внутренняя ошибка сервера"
}
}

View File

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

View File

@ -279,7 +279,7 @@ export async function checkInvite (invite: Invite | null, email: string): Promis
throw new PlatformError(new Status(Severity.ERROR, platform.status.Forbidden, {}))
}
if (invite.exp < Date.now()) {
throw new PlatformError(new Status(Severity.ERROR, platform.status.Forbidden, {}))
throw new PlatformError(new Status(Severity.ERROR, platform.status.ExpiredLink, {}))
}
if (!new RegExp(invite.emailMask).test(email)) {
throw new PlatformError(new Status(Severity.ERROR, platform.status.Forbidden, {}))
@ -924,6 +924,11 @@ function wrap (f: (db: Db, productId: string, ...args: any[]) => Promise<any>):
.then((result) => ({ id: request.id, result }))
.catch((err) => {
console.error(err)
if (err.status.code === platform.status.ExpiredLink) {
return {
error: new Status(Severity.ERROR, platform.status.ExpiredLink, {})
}
}
return {
error:
err instanceof PlatformError