Skip to content

Commit

Permalink
Throw nice error on 5xx responses
Browse files Browse the repository at this point in the history
  • Loading branch information
wojpawlik committed May 5, 2021
1 parent 1ab6563 commit e34c4d7
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/core/network/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,13 @@ class ApiClient {
config.agent = options.agent
config.signal = signal
const res = await fetch(apiUrl, config).catch(redactToken)
if (res.status >= 500) {
const errorPayload = {
error_code: res.status,
description: res.statusText,
}
throw new TelegramError(errorPayload, { method, payload })
}
const data = await res.json()
if (!data.ok) {
debug('API call failed', data)
Expand Down

0 comments on commit e34c4d7

Please sign in to comment.