generated from VLADIMIR/template_frontend
add update
This commit is contained in:
+12
-2
@@ -25,11 +25,21 @@ function createAuthHttpHandler(
|
||||
handler: (request: { path: string; method: string; body: string | null }) => Promise<unknown>,
|
||||
): (request: { path: string; method: string; body: string | null }) => Promise<unknown> {
|
||||
return async (request: { path: string; method: string; body: string | null }) => {
|
||||
let response: unknown
|
||||
try {
|
||||
return await handler(request)
|
||||
response = await handler(request)
|
||||
} catch {
|
||||
await refreshTokens()
|
||||
return await handler(request)
|
||||
response = await handler(request)
|
||||
}
|
||||
// Gateway возвращает gRPC-ошибки как JSON даже при HTTP 403/400/500.
|
||||
if (response && typeof response === 'object' && 'code' in response && response.code !== 0) {
|
||||
throw new Error(
|
||||
'message' in response && typeof response.message === 'string'
|
||||
? response.message
|
||||
: 'Ошибка запроса',
|
||||
)
|
||||
}
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user