How to use the ServiceUnavailable function from http-errors

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

146
147
148
149
150
151
152
153
154
155
badGateway: function badGateway (message) {
  return new createError.BadGateway(message)
},

serviceUnavailable: function serviceUnavailable (message) {
  return new createError.ServiceUnavailable(message)
},

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

+ 55 other calls in file

112
113
114
115
116
117
118
119
120
121
request({ method: req.method, url, qs, headers: requestHeaders, body }, (err, res) => {
  if (err) {
    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

299
300
301
302
303
304
305
306
307
308
    throw new HttpErrors.Unauthorized("User is technical only");
  }

  if (member.type === "ldap") {
    this.log("debug", "login", "FINISHED");
    throw new HttpErrors.ServiceUnavailable("No LDAP connection");
  }
}

credentials.ttl = ttl;
fork icon1
star icon8
watch icon0

13
14
15
16
17
18
19
20
21
22
23
app.get('/', (req, res) => {
  res.json({ greeting: 'Hello' });
});


app.get('/users', (req, res) => {
  throw createError.ServiceUnavailable(
    'An error has occurred when try to get all users because the database failure!'
  );
  // throw createError(404, 'An error has occurred when try to get all users  because the database failure!');
  // throw new Error('not found');
fork icon1
star icon0
watch icon0

172
173
174
175
176
177
178
179
180
181
module.exports.RequestHeaderFieldsTooLarge = new HTTPErrors.RequestHeaderFieldsTooLarge()
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()
fork icon1
star icon0
watch icon7

+ 41 other calls in file

316
317
318
319
320
321
322
323
324
325
      limit
    );
    try {
      return res.status(200).json(result);
    } catch (error) {
      throw createError.ServiceUnavailable("Something went wrong");
    }
  }
} catch (error) {
  next(error);
fork icon0
star icon1
watch icon0

222
223
224
225
226
227
228
229
230
231
  } else {
    const note = await findNoteById(id);
    try {
      return res.status(200).json({ note });
    } catch (error) {
      throw createError.ServiceUnavailable(error.message);
    }
  }
} catch (error) {
  next(error.message);
fork icon0
star icon1
watch icon0

6
7
8
9
10
11
12
13
14
15
16
const {add} = require("../common/models");


async function getAdAccount(adAccountId, token) {
  const url = `${FB_API_URL}act_${adAccountId}?access_token=${token}&fields=${fieldsFilter}`;
  const account = await axios.get(url).catch((err) => {
    throw new ServiceUnavailable(err.response?.data.error || err);
  });
  return account.data;
}

fork icon0
star icon0
watch icon0

169
170
171
172
173
174
175
176
177
178
case 502: {
  httpError = createError.BadGateway();
  break;
}
case 503: {
  httpError = createError.ServiceUnavailable();
  break;
}
case 504: {
  httpError = createError.GatewayTimeout();
fork icon0
star icon0
watch icon2

+ 41 other calls in file