How to use the NotAcceptable function from http-errors

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

39
40
41
42
43
44
45
46
47
48
methodNotAllowed: function methodNotAllowed (message) {
  return new createError.MethodNotAllowed(message)
},

notAcceptable: function notAcceptable (message) {
  return new createError.NotAcceptable(message)
},

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

+ 55 other calls in file

146
147
148
149
150
151
152
153
154
155
module.exports.BadRequest = new HTTPErrors.BadRequest()
module.exports.Unauthorized = new HTTPErrors.Unauthorized()
module.exports.Forbidden = new HTTPErrors.Forbidden()
module.exports.NotFound = new HTTPErrors.NotFound()
module.exports.MethodNotAllowed = new HTTPErrors.MethodNotAllowed()
module.exports.NotAcceptable = new HTTPErrors.NotAcceptable()
module.exports.ProxyAuthenticationRequired = new HTTPErrors.ProxyAuthenticationRequired()
module.exports.RequestTimeout = new HTTPErrors.RequestTimeout()
module.exports.Conflict = new HTTPErrors.Conflict()
module.exports.Gone = new HTTPErrors.Gone()
fork icon1
star icon0
watch icon7

+ 41 other calls in file

43
44
45
46
47
48
49
50
51
52
  throw createError.Conflict("Email or username has already been taken");
} else {
  // *** Hash user password
  const hash = await generateHashPassword(result.password);
  if (!hash) {
    throw createError.NotAcceptable("Weak password. Try again.");
  } else {
    const newUser = await saveNewUser(result, hash);
    if (!newUser) {
      throw createError.InternalServerError();
fork icon0
star icon1
watch icon0

89
90
91
92
93
94
95
96
97
98
const id = req.params.id;
if (!id) {
  throw createError.NotAcceptable("Request params is not present");
} else {
  if (!req.files) {
    throw createError.NotAcceptable("No image file is present");
  } else {
    const file = req.files.image;
    const data = await uploadImage(file);
    const result = await uploadGroupImage(id, "image", data.url);
fork icon0
star icon1
watch icon0

+ 5 other calls in file

80
81
82
83
84
85
86
87
88
if (!paramsLength) throw new createErrors.BadRequest('Request parameters empty')

const decryptVerificationCode = legacyDecrypt(params.code)
const user = await knex.select('*').from('users').where('verification_code', decryptVerificationCode).first()

if (!user) throw new createErrors.NotAcceptable('Verification code is not valid')

const id = user.id
const result = await knex('users').where('id', id).update('verification_code', '').returning('name')
fork icon4
star icon2
watch icon0

+ 3 other calls in file

84
85
86
87
88
89
90
91
92
93
if (!paramsLength) throw new createErrors.BadRequest('Request parameters empty!')

const decryptVerificationCode = legacyDecrypt(params.code)
const user = await getUserByIdModels(false, [decryptVerificationCode], 'verification_code = $1')

if (!user) throw new createErrors.NotAcceptable('Verification code is not valid!')

const id = user.id
const queryAdditionalDatabase = 'verification_code = \'\' WHERE id = $1'
const result = await putUserModels(false, [id], queryAdditionalDatabase)
fork icon0
star icon0
watch icon0

+ 23 other calls in file

183
184
185
186
187
188
189
190
191
192
    template: true,
  },
});

if (!pin)
  throw new createErrors.NotAcceptable("OTP Session was not found");

const expiryTime = moment
  .tz(SERVER_TIMEZONE)
  .utc()
fork icon0
star icon0
watch icon0

+ 7 other calls in file

49
50
51
52
53
54
55
56
57
        user.email,
        "Your account has login in other IP",
        "We detected your account has login in other IP. Please check it."
    );

    throw createError.NotAcceptable("Your ip has change. Please login again.");
}

if (!user) throw createError.Unauthorized("User dose not exists in database.");
fork icon0
star icon0
watch icon0

46
47
48
49
50
51
52
53
54
55
tokenAuthorization,
hasRole('user'),
async (req, res) => {
  const debug = _debug('api:is-unique');
  const { db, view, key } = req.params;
  if (!db || !view || !key) throw new NotAcceptable('invalid path');
  const uri =
    `${APPLICATION_ID}-${db}` +
    `/_design/${APPLICATION_ID}-api` +
    `/_view/${view}` +
fork icon0
star icon0
watch icon0

73
74
75
76
77
78
79
80
81
82
case 405: {
  httpError = createError.MethodNotAllowed();
  break;
}
case 406: {
  httpError = createError.NotAcceptable();
  break;
}
case 407: {
  httpError = createError.ProxyAuthenticationRequired();
fork icon0
star icon0
watch icon2

+ 41 other calls in file