How to use the UnsupportedMediaType function from http-errors

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

75
76
77
78
79
80
81
82
83
84
uriTooLong: function uriTooLong (message) {
  return new createError.URITooLong(message)
},

unsupportedMediaType: function unsupportedMediaType (message) {
  return new createError.UnsupportedMediaType(message)
},

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

+ 55 other calls in file

135
136
137
138
139
140
141
142
143
144
pipeline(file, extract, (error) => {
    if (error) {
        switch (error.code) {
            case 'TAR_BAD_ARCHIVE':
            case 'TAR_ABORT':
                reject(new HttpError.UnsupportedMediaType());
                break;
            case 'TAR_ENTRY_UNSUPPORTED':
            case 'TAR_ENTRY_INVALID':
            case 'TAR_ENTRY_ERROR':
fork icon2
star icon1
watch icon1

26
27
28
29
30
31
32
33
34
35
36
  });


const fileFilter = (req, file, cb) => {
  if (!file.originalname.match(/\.(jpg|JPG|jpeg|JPEG|png|PNG|gif)$/)) {
    return cb(
      createHttpError.UnsupportedMediaType(
        "Only images are allowed. [jpg|JPG|jpeg|JPEG|png|PNG|gif]"
      ),
      false
    );
fork icon2
star icon4
watch icon0

22
23
24
25
26
27
28
29
30
31
  cb(null, true);
} else {
  cb(
    null,
    false,
    new UnsupportedMediaType(
      'Unsupported file format. File should have png, jpeg or jpg formats'
    )
  );
}
fork icon1
star icon2
watch icon0

+ 2 other calls in file

155
156
157
158
159
160
161
162
163
164
module.exports.Gone = new HTTPErrors.Gone()
module.exports.LengthRequired = new HTTPErrors.LengthRequired()
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()
fork icon1
star icon0
watch icon7

+ 41 other calls in file

56
57
58
59
60
61
62
63
64
65
await cloudinary.v2.uploader.upload(file[0].path, {
  use_filename: false,
  unique_filename: true,
  overwrite: true
}, (pictureError, pictureResponse) => {
  if (pictureError) throw new createErrors.UnsupportedMediaType(`Profile picture: ${pictureError.message}`)

  fs.unlinkSync(file[0].path)

  data.picture = pictureResponse.secure_url || ''
fork icon0
star icon0
watch icon0

14
15
16
17
18
19
20
21
22
23
  const mimetype = filetypes.test(file.mimetype)

  if (mimetype && extname) {
    cb(null, true)
  } else {
    cb(new createErrors.UnsupportedMediaType('File type not allowed!'), false)
  }
},
limits: {
  fileSize: MAX_FILE_SIZE * 1024 * 1024
fork icon0
star icon0
watch icon0

109
110
111
112
113
114
115
116
117
118
case 414: {
  httpError = createError.URITooLong();
  break;
}
case 415: {
  httpError = createError.UnsupportedMediaType();
  break;
}
case 416: {
  httpError = createError.RangeNotSatisfiable();
fork icon0
star icon0
watch icon2

+ 41 other calls in file