Add Unsupported Media Type Exception (#11096)

* add unsuported media type exception

* throw error when not multipart/form-data

* use unsupportedMediaType when checking import file

* add `UNSUPPORTED_MEDIA_TYPE` to Error Codes docs
This commit is contained in:
Azri Kahar
2022-01-17 23:09:26 +08:00
committed by GitHub
parent 3d4602493c
commit 74bb4a7c9a
6 changed files with 36 additions and 18 deletions

View File

@@ -2,7 +2,12 @@ import argon2 from 'argon2';
import { Router } from 'express';
import Joi from 'joi';
import { nanoid } from 'nanoid';
import { ForbiddenException, InvalidPayloadException, InvalidQueryException } from '../exceptions';
import {
ForbiddenException,
InvalidPayloadException,
InvalidQueryException,
UnsupportedMediaTypeException,
} from '../exceptions';
import collectionExists from '../middleware/collection-exists';
import { respond } from '../middleware/respond';
import { RevisionsService, UtilsService, ImportService } from '../services';
@@ -94,6 +99,9 @@ router.post(
'/import/:collection',
collectionExists,
asyncHandler(async (req, res, next) => {
if (req.is('multipart/form-data') === false)
throw new UnsupportedMediaTypeException(`Unsupported Content-Type header`);
const service = new ImportService({
accountability: req.accountability,
schema: req.schema,