How to use the ExpectationFailed function from http-errors

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

83
84
85
86
87
88
89
90
91
92
rangeNotSatisfiable: function rangeNotSatisfiable (message) {
  return new createError.RangeNotSatisfiable(message)
},

expectationFailed: function expectationFailed (message) {
  return new createError.ExpectationFailed(message)
},

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

+ 55 other calls in file

109
110
111
112
113
114
115
116
117
118
const bodyLength = Object.keys(data).length
const user = await knex.select('*').from('users').where('email', data.email).first()
const sessionToken = req.signedCookies?.token

if (!bodyLength) throw new createErrors.BadRequest('Request body empty')
if (!user) throw new createErrors.ExpectationFailed('Unregistered account')
if (sessionToken) throw new createErrors.UnprocessableEntity('Session still active, you need to log out')
if (user?.verification_code) throw new createErrors.UnprocessableEntity('Account need to verification')

const verifyPassword = await argon2.verify(user.password, data.password)
fork icon4
star icon2
watch icon0

157
158
159
160
161
162
163
164
165
166
module.exports.PreconditionFailed = new HTTPErrors.PreconditionFailed()
module.exports.PayloadTooLarge = new HTTPErrors.PayloadTooLarge()
module.exports.URITooLong = new HTTPErrors.URITooLong()
module.exports.UnsupportedMediaType = new HTTPErrors.UnsupportedMediaType()
module.exports.RangeNotSatisfiable = new HTTPErrors.RangeNotSatisfiable()
module.exports.ExpectationFailed = new HTTPErrors.ExpectationFailed()
module.exports.ImATeapot = new HTTPErrors.ImATeapot()
module.exports.MisdirectedRequest = new HTTPErrors.MisdirectedRequest()
module.exports.UnprocessableEntity = new HTTPErrors.UnprocessableEntity()
module.exports.Locked = new HTTPErrors.Locked()
fork icon1
star icon0
watch icon7

+ 41 other calls in file

114
115
116
117
118
119
120
121
122
123
const bodyLength = Object.keys(data).length
const user = await getUserByIdModels(false, [data.email], 'email = $1')
const sessionToken = req.signedCookies?.token

if (!bodyLength) throw new createErrors.BadRequest('Request body empty!')
if (!user) throw new createErrors.ExpectationFailed('Unregistered account!')
if (sessionToken) throw new createErrors.UnprocessableEntity('Session still active, you need to log out!')
if (user?.verification_code !== '') throw new createErrors.UnprocessableEntity('Account need to verification!')

const verifyPassword = await argon2.verify(user?.password, data.password)
fork icon0
star icon0
watch icon0

+ 11 other calls in file

137
138
139
140
141
142
143
144
145
146
}

const user = await getUserByIdModels(false, [params.id], 'id = $1')

if (!user) {
  throw new createErrors.ExpectationFailed('Unregistered account!')
}

if (data?.password) {
  const hashPassword = await argon2.hash(data.password, {
fork icon0
star icon0
watch icon0

9
10
11
12
13
14
15
16
17
18
19
20


exports.getUser =  (email) => {
  try {
    // checking for any error occurance
    //const { email } = req.payload
    if (!email) throw creatError.ExpectationFailed("email")
    
    let userData = db.get(email)


    if (!userData) throw creatError.NotFound()
fork icon0
star icon0
watch icon0

40
41
42
43
44
45
46
47
48

const user = await knex.select('name').from('users').where('id', id).first()

if (!user) throw new createErrors.ExpectationFailed('Unregistered account')

if (userData.id !== id) throw new createErrors.ExpectationFailed('Your profile ID did not match with session')

if (data?.password) {
  const hashPassword = await argon2.hash(data.password, { type: argon2.argon2id })
fork icon0
star icon0
watch icon0

+ 2 other calls in file

117
118
119
120
121
122
123
124
125
126
case 416: {
  httpError = createError.RangeNotSatisfiable();
  break;
}
case 417: {
  httpError = createError.ExpectationFailed();
  break;
}
case 418: {
  httpError = createError.ImATeapot();
fork icon0
star icon0
watch icon2

+ 41 other calls in file