0

hi guys i have code like this i can handle for give the response... my question is if i want to give bad_request how to set it ? because i have used this code but it is error

 @GetMapping("/reply/{message}")
        public ReplyMessage replying(@PathVariable String message) {
            StringBuilder input1 = new StringBuilder();
            if(message.contains("-")){
            String[] messageData = message.split("-");
            String cek1 = messageData[0];
            String cek2 = messageData[1];
    
            if(cek1.equals("1")){
                input1.append(cek2);
                return new ReplyMessage(input1.reverse().toString());
            }else if(cek1.equals("2")){
                    String md5Hex = DigestUtils.md5Hex(cek2);
                return new ReplyMessage(md5Hex);
            }else if(cek1.equals("11")){
                return new ReplyMessage(cek1);
            }else if(cek1.equals("12")){
                input1.append(cek2);
                String reverse =input1.reverse().toString();
                String md5Hex = DigestUtils.md5Hex(reverse);
                return new ReplyMessage(md5Hex);
            }else if(cek1.equals("22")){
                String md5Hex = DigestUtils.md5Hex(cek2);
                String md5Hex2x = DigestUtils.md5Hex(md5Hex);
                return new ReplyMessage(md5Hex2x);
            }
        }else{
            return new ReplyMessage(message);
        }
        throw new ResourceException(HttpStatus.BAD_REQUEST, "Invalid Input");
        }

my question is how to set at the bottom if process cannot handle by if else.. i can sent it as bad_request ? how to set that ?

aaaaaajib
  • 49
  • 4
  • Can you refer this link. Looks like this will solve your problem - https://stackoverflow.com/questions/16232833/how-to-respond-with-http-400-error-in-a-spring-mvc-responsebody-method-returnin – Vasanth Subramanian Sep 15 '21 at 11:32

0 Answers0