mirror of
https://github.com/valitydev/disputes-api.git
synced 2024-11-06 00:55:23 +00:00
use MediaType for validate
This commit is contained in:
parent
226be289e5
commit
29bc4e5800
@ -9,6 +9,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.InvalidMediaTypeException;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.InvalidMimeTypeException;
|
||||
@ -42,6 +43,14 @@ public class ErrorControllerAdvice {
|
||||
.message(e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler({InvalidMediaTypeException.class})
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public Object handleInvalidMediaTypeException(InvalidMediaTypeException e) {
|
||||
log.warn("<- Res [400]: MimeType not valid", e);
|
||||
return new GeneralError()
|
||||
.message(e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler({ConstraintViolationException.class})
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public Object handleConstraintViolationException(ConstraintViolationException e) {
|
||||
|
@ -7,10 +7,10 @@ import dev.vality.swag.disputes.model.CreateRequest;
|
||||
import dev.vality.swag.disputes.model.CreateRequestAttachmentsInner;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.MimeType;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@ -25,7 +25,8 @@ public class ApiAttachmentsService {
|
||||
public void createAttachments(CreateRequest req, Long disputeId) {
|
||||
log.debug("Trying to save Attachments {}", disputeId);
|
||||
for (CreateRequestAttachmentsInner attachment : req.getAttachments()) {
|
||||
MimeType.valueOf(attachment.getMimeType());
|
||||
// validate
|
||||
MediaType.valueOf(attachment.getMimeType());
|
||||
// http 500
|
||||
var fileId = fileStorageService.saveFile(attachment.getData());
|
||||
var fileMeta = new FileMeta(fileId, disputeId, attachment.getMimeType());
|
||||
|
Loading…
Reference in New Issue
Block a user