<commit_before>'use strict';

const helpers = require('../../helpers');
const NotFoundError = require('../../../app/exceptions/NotFoundError');

module.exports = function fetchUser(config) {
  return (req, res, next) => helpers.user.fetchFromReq(req)
    .then((user) => {
      helpers.request.setUser(req, user);

      return next();
    })
    .catch((err) => {
      if (err && err.status === 404) {
        if (!config.shouldSendErrorIfNotFound) {
          return next();
        }
        const error = new NotFoundError('Northstar user not found.');
        return helpers.sendErrorResponseWithSuppressHeaders(res, error);
      }

      return helpers.sendErrorResponse(res, err);
    });
};
<commit_msg>refactored user-get middleware to use async/await<commit_after>'use strict';

const helpers = require('../../helpers');
const NotFoundError = require('../../../app/exceptions/NotFoundError');

module.exports = function fetchUser(config) {
  return async (req, res, next) => {
    try {
      const user = await helpers.user.fetchFromReq(req);
      helpers.request.setUser(req, user);
      return next();
    } catch (error) {
      if (error && error.status === 404) {
        if (!config.shouldSendErrorIfNotFound) {
          return next();
        }
        const userNotFoundError = new NotFoundError('Northstar user not found.');
        return helpers.sendErrorResponseWithSuppressHeaders(res, userNotFoundError);
      }

      return helpers.sendErrorResponse(res, error);
    }
  };
};

{'fraction_non_alphanumeric': 0.14956982131039048, 'fraction_numerical': 0.003970880211780278, 'mean_word_length': 2.9272727272727272, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5610794', 'n_tokens_mistral': 440, 'n_tokens_neox': 435, 'n_words': 96}