From 83397b07dc8b5318edc1356a91631a471fd08ea9 Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Wed, 8 Jun 2022 12:39:46 +0200 Subject: [PATCH] openvidu-server: fix RPC missing parameters exception message --- .../io/openvidu/server/rpc/RpcHandler.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/openvidu-server/src/main/java/io/openvidu/server/rpc/RpcHandler.java b/openvidu-server/src/main/java/io/openvidu/server/rpc/RpcHandler.java index c21fc964..1f7384ec 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/rpc/RpcHandler.java +++ b/openvidu-server/src/main/java/io/openvidu/server/rpc/RpcHandler.java @@ -806,34 +806,28 @@ public class RpcHandler extends DefaultJsonRpcHandler { public static String getStringParam(Request request, String key) throws RuntimeException { if (request.getParams() == null || request.getParams().get(key) == null) { - throw new RuntimeException("Request element '" + key + "' is missing in method '" + request != null - ? request.getMethod() - : "[NO REQUEST OBJECT]" - + "'. Check that 'openvidu-server' AND 'openvidu-browser' versions are compatible with each other"); + throw missingParamException(request, key); } return request.getParams().get(key).getAsString(); } public static int getIntParam(Request request, String key) throws RuntimeException { if (request.getParams() == null || request.getParams().get(key) == null) { - throw new RuntimeException("Request element '" + key + "' is missing in method '" + request.getMethod() - + "'. Check that 'openvidu-server' AND 'openvidu-browser' versions are compatible with each other"); + throw missingParamException(request, key); } return request.getParams().get(key).getAsInt(); } public static boolean getBooleanParam(Request request, String key) throws RuntimeException { if (request.getParams() == null || request.getParams().get(key) == null) { - throw new RuntimeException("Request element '" + key + "' is missing in method '" + request.getMethod() - + "'. Check that 'openvidu-server' AND 'openvidu-browser' versions are compatible with each other"); + throw missingParamException(request, key); } return request.getParams().get(key).getAsBoolean(); } public static JsonElement getParam(Request request, String key) throws RuntimeException { if (request.getParams() == null || request.getParams().get(key) == null) { - throw new RuntimeException("Request element '" + key + "' is missing in method '" + request.getMethod() - + "'. Check that 'openvidu-server' AND 'openvidu-browser' versions are compatible with each other"); + throw missingParamException(request, key); } return request.getParams().get(key); } @@ -939,4 +933,11 @@ public class RpcHandler extends DefaultJsonRpcHandler { } } + private static RuntimeException missingParamException(Request request, String key) { + String err = "Request element '" + key + "' is missing in RPC method "; + err += (request != null) ? ("'" + request.getMethod() + "'") : "[NO REQUEST OBJECT]"; + err += ". Check that 'openvidu-server' and 'openvidu-browser' versions are compatible with each other"; + throw new RuntimeException(err); + } + }