How to use the http-status-codes.SERVICE_UNAVAILABLE function in http-status-codes

To help you get started, we’ve selected a few http-status-codes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Borewit / musicbrainz-api / src / musicbrainz-api.ts View on Github external
}, null);
      if (response.statusCode !== 503)
        break;
      debug('Rate limiter kicked in, slowing down...');
      await RateLimiter.sleep(500);
    } while (true);

    switch (response.statusCode) {
      case HttpStatus.OK:
        return response.body;

      case HttpStatus.BAD_REQUEST:
      case HttpStatus.NOT_FOUND:
        throw new Error(`Got response status ${response.statusCode}: ${HttpStatus.getStatusText(response.statusCode)}`);

      case HttpStatus.SERVICE_UNAVAILABLE: // 503
      default:
        const msg = `Got response status ${response.statusCode} on attempt #${attempt} (${HttpStatus.getStatusText(response.statusCode)})`;
        debug(msg);
        if (attempt < retries) {
          return this.restGet(relUrl, query, attempt + 1);
        } else
          throw new Error(msg);
    }
  }
github Prior99 / hyrest / packages / hyrest / src / answers.ts View on Github external
export function serviceUnavailable(arg1: T | string | Wrapper, arg2?: string): T {
    return answer(HTTP.SERVICE_UNAVAILABLE, arg1, arg2);
}
github RequestNetwork / requestNetwork / packages / request-node / src / requestNode.ts View on Github external
router.get('/getChannelsByTopic', (clientRequest: any, serverResponse: any) => {
      if (this.initialized) {
        return getChannelsByTopic(clientRequest, serverResponse, this.dataAccess, this.logger);
      } else {
        return serverResponse.status(httpStatus.SERVICE_UNAVAILABLE).send(NOT_INITIALIZED_MESSAGE);
      }
    });
github stanislav-web / ecs-auth-microservice / app / src / api / access / controller.js View on Github external
let isAuth = await compare(res.value.password.trim(), dbuser.password);
            if (isAuth) {
                let obj = await generateTokenObject(res.value);

                try {
                    await updateUser(dbuser._id || dbuser.email);
                    ctx.body = {
                        status: HttpStatus.OK,
                        message: {
                            expires_in: obj.expires_in,
                            token: obj.token
                        }
                    };
                } catch (err) {
                    throw new ApiAccessBoundleError(
                        HttpStatus.SERVICE_UNAVAILABLE, err.message
                    );
                }
            } else {
                throw new ApiAccessBoundleError(
                    HttpStatus.FORBIDDEN, 'Invalid credentials'
                );
            }
        } else {
            throw new ApiAccessBoundleError(
                HttpStatus.NOT_FOUND, 'User not found'
            );
        }
    } else {
        throw new ApiAccessBoundleError(
            HttpStatus.BAD_REQUEST, res.error.message
        );
github AceMetrix / connect-cas / lib / service-validate.js View on Github external
return function(req,res,next){
        var options = _.extend({}, configuration, overrides);
        var pgtPathname = pgtPath(options);
        if (!options.host && !options.hostname) throw new Error('no CAS host specified');
        if (options.pgtFn && !options.pgtUrl) throw new Error('pgtUrl must be specified for obtaining proxy tickets');

        if (!req.session){
            res.send(HttpStatus.SERVICE_UNAVAILABLE);
            return;
        }

        var url = parseUrl(req.url, true);
        var ticket = (url.query && url.query.ticket) ? url.query.ticket : null;

        options.query = options.query || {};
        options.query.service = origin(req);
        options.query.ticket = ticket;
        options.pathname = options.paths.serviceValidate;

        if (options.pgtUrl || options.query.pgtUrl)
            options.query.pgtUrl = pgtPathname ? req.protocol + '://' + req.get('host') + pgtPathname : options.pgtUrl;

        if (pgtPathname && req.path === pgtPathname && req.method === 'GET') {
            if (!req.query.pgtIou || !req.query.pgtId) return res.send(HttpStatus.OK);
github daGrevis / msks / backend / src / server / routes / commands.js View on Github external
router.post('/connect', withAuthenticated, withConnection, async ctx => {
  const state = store.getState()

  const { connection } = ctx

  if (state.isIrcClientConnected[connection.id]) {
    ctx.body = { error: 'Already connected to IRC!' }
    ctx.status = HttpStatus.SERVICE_UNAVAILABLE
    return
  }

  const nextConnection = await updateConnection(
    { id: connection.id },
    { autoConnect: true },
  )
  store.dispatch({
    type: 'SYNC_POSTGRES',
    payload: {
      table: 'connections',
      change: { next: nextConnection },
    },
  })

  connect(nextConnection)