How to use the statuses function in statuses

To help you get started, we’ve selected a few statuses 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 juliaqiuxy / slopeninja-backend / src / api.js View on Github external
const resortService = new ResortService();

  let resort;

  try {
    resort = await resortService.findByShortName(shortName);
  } catch (error) {
    // network or db error
    ctx.status = statuses('Internal Server Error');
    return;
  }

  if (!resort) {
    // cannot find resort
    ctx.status = statuses('Not Found');
    return;
  }

  ctx.status = statuses('OK');
  ctx.body = {
    resort,
  };
});
github juliaqiuxy / slopeninja-backend / src / api.js View on Github external
const mailchimpResponse = await fetch('https://us15.api.mailchimp.com/3.0/lists/b56b3d32c5/members', {
    method: 'POST',
    headers:
    new Headers({
      authorization: `Basic ${token}`,
      'content-type': 'application/json',
    }),
    body: JSON.stringify({
      email_address: ctx.request.body.email,
      status: 'subscribed',
    }),
  });

  const mailchimpResponseBody = await mailchimpResponse.json();

  if (mailchimpResponse.status !== statuses('OK')) {
    if (mailchimpResponse.status === statuses('Bad Request')) {
      ctx.status = statuses('Bad Request');
      ctx.body = {
        error: mailchimpResponseBody.title,
      };
    } else {
      ctx.status = statuses('Internal Server Error');
      ctx.body = {
        error: 'Opps. Something\'s not right.',
      };
    }

    return;
  }

  ctx.status = statuses('OK');
github juliaqiuxy / slopeninja-backend / src / api.js View on Github external
router.get('/newsletters/latest', async (ctx) => {
  const newsletterService = new NewsletterService();
  const newsletterSample = await newsletterService.getNewsletterSample();
  ctx.status = statuses('OK');
  ctx.body = newsletterSample;
});
github juliaqiuxy / slopeninja-backend / src / api.js View on Github external
router.post('/user-devices', async (ctx) => {
  const schema = Joi.object().keys({
    deviceName: Joi.string(),
    notificationToken: Joi.string().required(),
  });

  const { error } = Joi.validate({
    deviceName: ctx.request.body.deviceName,
    notificationToken: ctx.request.body.notificationToken,
  }, schema);

  if (error) {
    ctx.status = statuses('Bad Request');
    ctx.body = {
      error: error.message,
    };
    return;
  }

  const userDeviceService = new UserDeviceService();

  try {
    await userDeviceService.create(ctx.request.body.deviceName, ctx.request.body.notificationToken);
  } catch (e) {
    ctx.status = statuses('Internal Server Error');
    ctx.body = {
      error: 'Opps. Something\'s not right.',
    };
    return;
github juliaqiuxy / slopeninja-backend / src / api.js View on Github external
}, schema);

  if (error) {
    ctx.status = statuses('Bad Request');
    ctx.body = {
      error: error.message,
    };
    return;
  }

  const userDeviceService = new UserDeviceService();

  try {
    await userDeviceService.create(ctx.request.body.deviceName, ctx.request.body.notificationToken);
  } catch (e) {
    ctx.status = statuses('Internal Server Error');
    ctx.body = {
      error: 'Opps. Something\'s not right.',
    };
    return;
  }

  ctx.status = statuses('OK');
  ctx.body = {
    deviceName: ctx.request.body.deviceName,
    notificationToken: 'valid',
  };
});
github juliaqiuxy / slopeninja-backend / src / api.js View on Github external
method: 'POST',
    headers:
    new Headers({
      authorization: `Basic ${token}`,
      'content-type': 'application/json',
    }),
    body: JSON.stringify({
      email_address: ctx.request.body.email,
      status: 'subscribed',
    }),
  });

  const mailchimpResponseBody = await mailchimpResponse.json();

  if (mailchimpResponse.status !== statuses('OK')) {
    if (mailchimpResponse.status === statuses('Bad Request')) {
      ctx.status = statuses('Bad Request');
      ctx.body = {
        error: mailchimpResponseBody.title,
      };
    } else {
      ctx.status = statuses('Internal Server Error');
      ctx.body = {
        error: 'Opps. Something\'s not right.',
      };
    }

    return;
  }

  ctx.status = statuses('OK');
  ctx.body = {

statuses

HTTP status utility

MIT
Latest version published 3 years ago

Package Health Score

71 / 100
Full package analysis