How to use the PreconditionFailed function from http-errors

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

63
64
65
66
67
68
69
70
71
72
lengthRequired: function lengthRequired (message) {
  return new createError.LengthRequired(message)
},

preconditionFailed: function preconditionFailed (message) {
  return new createError.PreconditionFailed(message)
},

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

+ 55 other calls in file

124
125
126
127
128
129
130
131
132
133
}

if (req.headers['if-match']) {
  if (rev !== req.headers['if-match'].replace(/(^["']|["']$)/g, '')) {
    throw Object.assign(
      new httperr.PreconditionFailed('wrong revision'),
      {errorNum: errors.ERROR_GRAPH_INVALID_VERTEX.code}
    );
  }
}
fork icon813
star icon0
watch icon2

+ 3 other calls in file

106
107
108
109
110
111
112
113
114
115
}

async function validateDeletePreconditions ({ user, namespace }) {
  const shootList = await shoots.list({ user, namespace })
  if (!_.isEmpty(shootList.items)) {
    throw new PreconditionFailed('Only empty projects can be deleted')
  }
}

function getProjectName (namespace) {
fork icon87
star icon0
watch icon0

2
3
4
5
6
7
8
9
10
11

const middleware = () => {
    return ({
        before: (handler, next) => {
            if (!middleware().checkKmsConfig(handler.event)) {
                throw new createError.PreconditionFailed({ errors: [{ message: 'Precondition Failed: masterApiKey' }] });
            }
            return next();
        },
        checkKmsConfig: (event) => {
fork icon6
star icon103
watch icon9

22
23
24
25
26
27
28
29
30
31
        'The supplied email activation token is invalid or has expired'
)
module.exports.DeleteNotAllowed = new HTTPErrors.PreconditionFailed(
        'Cannot delete the supplied email because users should have at least one email address linked to their account'
)
module.exports.EmailAlreadyActivated = new HTTPErrors.PreconditionFailed(
        'This email is already active and cannot be activated again'
)

/* Entities related errors */
fork icon1
star icon0
watch icon7

+ 461 other calls in file

97
98
99
100
101
102
103
104
105
106
case 411: {
  httpError = createError.LengthRequired();
  break;
}
case 412: {
  httpError = createError.PreconditionFailed();
  break;
}
case 413: {
  httpError = createError.PayloadTooLarge();
fork icon0
star icon0
watch icon2

+ 41 other calls in file