Handle invalid requests gracefully.

This commit is contained in:
FireMasterK 2021-07-21 02:33:44 +05:30
parent d6e998eef7
commit a1ed146924
No known key found for this signature in database
GPG Key ID: 49451E4482CC5BCD
2 changed files with 17 additions and 0 deletions

View File

@ -84,6 +84,7 @@ import me.kavin.piped.utils.resp.AcceptedResponse;
import me.kavin.piped.utils.resp.AlreadyRegisteredResponse;
import me.kavin.piped.utils.resp.AuthenticationFailureResponse;
import me.kavin.piped.utils.resp.IncorrectCredentialsResponse;
import me.kavin.piped.utils.resp.InvalidRequestResponse;
import me.kavin.piped.utils.resp.LoginResponse;
import me.kavin.piped.utils.resp.SubscribeStatusResponse;
@ -263,6 +264,9 @@ public class ResponseHelper {
public static final byte[] trendingResponse(String region)
throws ParsingException, ExtractionException, IOException {
if (region == null)
return Constants.mapper.writeValueAsBytes(new InvalidRequestResponse());
final List<StreamItem> relatedStreams = new ObjectArrayList<>();
KioskList kioskList = Constants.YOUTUBE_SERVICE.getKioskList();
@ -515,6 +519,9 @@ public class ResponseHelper {
public static final byte[] registerResponse(String user, String pass)
throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
if (user == null || pass == null)
return Constants.mapper.writeValueAsBytes(new InvalidRequestResponse());
user = user.toLowerCase();
Session s = DatabaseSessionFactory.createSession();
@ -544,6 +551,9 @@ public class ResponseHelper {
public static final byte[] loginResponse(String user, String pass)
throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
if (user == null || pass == null)
return Constants.mapper.writeValueAsBytes(new InvalidRequestResponse());
user = user.toLowerCase();
Session s = DatabaseSessionFactory.createSession();

View File

@ -0,0 +1,7 @@
package me.kavin.piped.utils.resp;
public class InvalidRequestResponse {
public String message = "Invalid request sent.";
}