How to use the GatewayTimeout function from http-errors

Find comprehensive JavaScript http-errors.GatewayTimeout code examples handpicked from public code repositorys.

150
151
152
153
154
155
156
157
158
159
serviceUnavailable: function serviceUnavailable (message) {
  return new createError.ServiceUnavailable(message)
},

gatewayTimeout: function gatewayTimeout (message) {
  return new createError.GatewayTimeout(message)
},

httpVersionNotSupported: function httpVersionNotSupported (message) {
  return new createError.HTTPVersionNotSupported(message)
fork icon30
star icon340
watch icon17

+ 55 other calls in file

208
209
210
211
212
213
214
215
216
217
function waitFor (condition, { timeout = 5000 } = {}) {
  const watch = this
  const resourceName = this.resourceName
  return new Promise((resolve, reject) => {
    const timeoutId = setTimeout(() => {
      done(new GatewayTimeout(`Resource "${resourceName}" could not be initialized within ${timeout} ms`))
    }, timeout)

    function done (err, obj) {
      clearTimeout(timeoutId)
fork icon87
star icon0
watch icon1

114
115
116
117
118
119
120
121
122
123
this.request.log.warn(err, 'response errored')
if (!this.sent) {
  if (err.code === 'ERR_HTTP2_STREAM_CANCEL' || err.code === 'ENOTFOUND') {
    onError(this, { error: new createError.ServiceUnavailable() })
  } else if (err instanceof TimeoutError || err.code === 'UND_ERR_HEADERS_TIMEOUT') {
    onError(this, { error: new createError.GatewayTimeout() })
  } else {
    onError(this, { error: createError(500, err) })
  }
}
fork icon67
star icon0
watch icon0

5
6
7
8
9
10
11
12
13
14
try {
  return await fn(...args);
} catch (error) {
  // Failed request
  if (error.name === 'FetchError' && error.code === 'ETIMEDOUT') {
    throw createError.GatewayTimeout();
  }

  // Telegram error
  if (error.response && error.response.ok === false && error.response.description) {
fork icon1
star icon3
watch icon1

173
174
175
176
177
178
179
180
181
182
module.exports.UnavailableForLegalReasons = new HTTPErrors.UnavailableForLegalReasons()
module.exports.InternalServerError = new HTTPErrors.InternalServerError()
module.exports.NotImplemented = new HTTPErrors.NotImplemented()
module.exports.BadGateway = new HTTPErrors.BadGateway()
module.exports.ServiceUnavailable = new HTTPErrors.ServiceUnavailable()
module.exports.GatewayTimeout = new HTTPErrors.GatewayTimeout()
module.exports.HTTPVersionNotSupported = new HTTPErrors.HTTPVersionNotSupported()
module.exports.VariantAlsoNegotiates = new HTTPErrors.VariantAlsoNegotiates()
module.exports.InsufficientStorage = new HTTPErrors.InsufficientStorage()
module.exports.LoopDetected = new HTTPErrors.LoopDetected()
fork icon1
star icon0
watch icon7

+ 41 other calls in file

173
174
175
176
177
178
179
180
181
182
case 503: {
  httpError = createError.ServiceUnavailable();
  break;
}
case 504: {
  httpError = createError.GatewayTimeout();
  break;
}
case 505: {
  httpError = createError.HTTPVersionNotSupported();
fork icon0
star icon0
watch icon2

+ 41 other calls in file