mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: REST error responses extended
parent
2b358f6497
commit
d884555cbd
|
@ -86,11 +86,22 @@ public class SessionRestController {
|
||||||
String customSessionId = null;
|
String customSessionId = null;
|
||||||
|
|
||||||
if (params != null) {
|
if (params != null) {
|
||||||
String mediaModeString = (String) params.get("mediaMode");
|
|
||||||
String recordingModeString = (String) params.get("recordingMode");
|
String mediaModeString;
|
||||||
String defaultOutputModeString = (String) params.get("defaultOutputMode");
|
String recordingModeString;
|
||||||
String defaultRecordingLayoutString = (String) params.get("defaultRecordingLayout");
|
String defaultOutputModeString;
|
||||||
String defaultCustomLayout = (String) params.get("defaultCustomLayout");
|
String defaultRecordingLayoutString;
|
||||||
|
String defaultCustomLayout;
|
||||||
|
try {
|
||||||
|
mediaModeString = (String) params.get("mediaMode");
|
||||||
|
recordingModeString = (String) params.get("recordingMode");
|
||||||
|
defaultOutputModeString = (String) params.get("defaultOutputMode");
|
||||||
|
defaultRecordingLayoutString = (String) params.get("defaultRecordingLayout");
|
||||||
|
defaultCustomLayout = (String) params.get("defaultCustomLayout");
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
return this.generateErrorResponse("Type error in some parameter", "/api/sessions",
|
||||||
|
HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
customSessionId = (String) params.get("customSessionId");
|
customSessionId = (String) params.get("customSessionId");
|
||||||
|
|
||||||
|
@ -130,7 +141,7 @@ public class SessionRestController {
|
||||||
return this.generateErrorResponse("RecordingMode " + params.get("recordingMode") + " | "
|
return this.generateErrorResponse("RecordingMode " + params.get("recordingMode") + " | "
|
||||||
+ "Default OutputMode " + params.get("defaultOutputMode") + " | " + "Default RecordingLayout "
|
+ "Default OutputMode " + params.get("defaultOutputMode") + " | " + "Default RecordingLayout "
|
||||||
+ params.get("defaultRecordingLayout") + " | " + "MediaMode " + params.get("mediaMode")
|
+ params.get("defaultRecordingLayout") + " | " + "MediaMode " + params.get("mediaMode")
|
||||||
+ " are not defined", "/api/tokens", HttpStatus.BAD_REQUEST);
|
+ ". Some parameter is not defined", "/api/sessions", HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,15 +259,26 @@ public class SessionRestController {
|
||||||
|
|
||||||
log.info("REST API: POST /api/tokens {}", params.toString());
|
log.info("REST API: POST /api/tokens {}", params.toString());
|
||||||
|
|
||||||
|
String sessionId;
|
||||||
|
String roleString;
|
||||||
|
String metadata;
|
||||||
try {
|
try {
|
||||||
String sessionId = (String) params.get("session");
|
sessionId = (String) params.get("session");
|
||||||
String roleString = (String) params.get("role");
|
roleString = (String) params.get("role");
|
||||||
String metadata = (String) params.get("data");
|
metadata = (String) params.get("data");
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
return this.generateErrorResponse("Type error in some parameter", "/api/tokens", HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
JsonObject kurentoOptions = null;
|
JsonObject kurentoOptions = null;
|
||||||
|
|
||||||
if (params.get("kurentoOptions") != null) {
|
if (params.get("kurentoOptions") != null) {
|
||||||
|
try {
|
||||||
kurentoOptions = new JsonParser().parse(params.get("kurentoOptions").toString()).getAsJsonObject();
|
kurentoOptions = new JsonParser().parse(params.get("kurentoOptions").toString()).getAsJsonObject();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return this.generateErrorResponse("Error in parameter 'kurentoOptions'. It is not a valid JSON object",
|
||||||
|
"/api/tokens", HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ParticipantRole role;
|
ParticipantRole role;
|
||||||
|
@ -267,7 +289,7 @@ public class SessionRestController {
|
||||||
role = ParticipantRole.PUBLISHER;
|
role = ParticipantRole.PUBLISHER;
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
return this.generateErrorResponse("Role " + params.get("role") + " is not defined", "/api/tokens",
|
return this.generateErrorResponse("Parameter role " + params.get("role") + " is not defined", "/api/tokens",
|
||||||
HttpStatus.BAD_REQUEST);
|
HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,14 +298,20 @@ public class SessionRestController {
|
||||||
try {
|
try {
|
||||||
kurentoTokenOptions = new KurentoTokenOptions(kurentoOptions);
|
kurentoTokenOptions = new KurentoTokenOptions(kurentoOptions);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return this.generateErrorResponse("Error in some parameter of 'kurentoOptions'", "/api/tokens",
|
return this.generateErrorResponse("Type error in some parameter of 'kurentoOptions'", "/api/tokens",
|
||||||
HttpStatus.BAD_REQUEST);
|
HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata = (metadata != null) ? metadata : "";
|
metadata = (metadata != null) ? metadata : "";
|
||||||
|
|
||||||
String token = sessionManager.newToken(sessionId, role, metadata, kurentoTokenOptions);
|
String token;
|
||||||
|
try {
|
||||||
|
token = sessionManager.newToken(sessionId, role, metadata, kurentoTokenOptions);
|
||||||
|
} catch (OpenViduException e) {
|
||||||
|
// Session was not found
|
||||||
|
return this.generateErrorResponse(e.getMessage(), "/api/tokens", HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
JsonObject responseJson = new JsonObject();
|
JsonObject responseJson = new JsonObject();
|
||||||
responseJson.addProperty("id", token);
|
responseJson.addProperty("id", token);
|
||||||
responseJson.addProperty("session", sessionId);
|
responseJson.addProperty("session", sessionId);
|
||||||
|
@ -319,10 +347,6 @@ public class SessionRestController {
|
||||||
responseJson.add("kurentoOptions", kurentoOptsResponse);
|
responseJson.add("kurentoOptions", kurentoOptsResponse);
|
||||||
}
|
}
|
||||||
return new ResponseEntity<>(responseJson.toString(), getResponseHeaders(), HttpStatus.OK);
|
return new ResponseEntity<>(responseJson.toString(), getResponseHeaders(), HttpStatus.OK);
|
||||||
} catch (OpenViduException e) {
|
|
||||||
// sessionId was not found
|
|
||||||
return this.generateErrorResponse(e.getMessage(), "/api/tokens", HttpStatus.NOT_FOUND);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/recordings/start", method = RequestMethod.POST)
|
@RequestMapping(value = "/recordings/start", method = RequestMethod.POST)
|
||||||
|
@ -330,18 +354,32 @@ public class SessionRestController {
|
||||||
|
|
||||||
log.info("REST API: POST /api/recordings/start {}", params.toString());
|
log.info("REST API: POST /api/recordings/start {}", params.toString());
|
||||||
|
|
||||||
String sessionId = (String) params.get("session");
|
String sessionId;
|
||||||
String name = (String) params.get("name");
|
String name;
|
||||||
String outputModeString = (String) params.get("outputMode");
|
String outputModeString;
|
||||||
String resolution = (String) params.get("resolution");
|
String resolution;
|
||||||
Boolean hasAudio = (Boolean) params.get("hasAudio");
|
Boolean hasAudio;
|
||||||
Boolean hasVideo = (Boolean) params.get("hasVideo");
|
Boolean hasVideo;
|
||||||
String recordingLayoutString = (String) params.get("recordingLayout");
|
String recordingLayoutString;
|
||||||
String customLayout = (String) params.get("customLayout");
|
String customLayout;
|
||||||
|
try {
|
||||||
|
sessionId = (String) params.get("session");
|
||||||
|
name = (String) params.get("name");
|
||||||
|
outputModeString = (String) params.get("outputMode");
|
||||||
|
resolution = (String) params.get("resolution");
|
||||||
|
hasAudio = (Boolean) params.get("hasAudio");
|
||||||
|
hasVideo = (Boolean) params.get("hasVideo");
|
||||||
|
recordingLayoutString = (String) params.get("recordingLayout");
|
||||||
|
customLayout = (String) params.get("customLayout");
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
return this.generateErrorResponse("Type error in some parameter", "/api/recordings/start",
|
||||||
|
HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
if (sessionId == null) {
|
if (sessionId == null) {
|
||||||
// "session" parameter not found
|
// "session" parameter not found
|
||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
return this.generateErrorResponse("session parameter is mandatory", "/api/recordings/start",
|
||||||
|
HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.openviduConfig.isRecordingModuleEnabled()) {
|
if (!this.openviduConfig.isRecordingModuleEnabled()) {
|
||||||
|
@ -357,7 +395,7 @@ public class SessionRestController {
|
||||||
}
|
}
|
||||||
if (session.getParticipants().isEmpty()) {
|
if (session.getParticipants().isEmpty()) {
|
||||||
// Session has no participants
|
// Session has no participants
|
||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
|
||||||
}
|
}
|
||||||
if (!(session.getSessionProperties().mediaMode().equals(MediaMode.ROUTED))
|
if (!(session.getSessionProperties().mediaMode().equals(MediaMode.ROUTED))
|
||||||
|| this.recordingManager.sessionIsBeingRecorded(session.getSessionId())) {
|
|| this.recordingManager.sessionIsBeingRecorded(session.getSessionId())) {
|
||||||
|
|
Loading…
Reference in New Issue