For the below code when I am trying to hit through through postman it is working fine when the file is attached only. But when a file is not attached it is throwing an internal server error it was there below. but in my case, if the file is not attached also it needs to work. Thanks in advance
@PostMapping("add")
public ResponseEntity<JSONObject> addProject(
@RequestPart(required = false, value = "file") MultipartFile file,
@RequestPart(value = "jsonObject", required = false) JSONObject jsonObject) {
JSONObject responseJsonObject = null;
try {
responseJsonObject = service.addProject(request, response, file, jsonObject);
} catch (Exception e) {
LOGGER.error("Error in addProject() method !!", e);
}
return new ResponseEntity<JSONObject>(responseJsonObject, HttpStatus.CREATED);
}
The response in postman when the file is not attached:
<!doctype html>
<html lang="en">
<head>
<title>HTTP Status 500 – Internal Server Error</title>
<style type="text/css">
body {
font-family: Tahoma, Arial, sans-serif;
}
h1,
h2,
h3,
b {
color: white;
background-color: #525D76;
}
h1 {
font-size: 22px;
}
h2 {
font-size: 16px;
}
h3 {
font-size: 14px;
}
p {
font-size: 12px;
}
a {
color: black;
}
.line {
height: 1px;
background-color: #525D76;
border: none;
}
</style>
</head>
<body>
<h1>HTTP Status 500 – Internal Server Error</h1>
</body>
</html>