getSecretKey jsonResult getNoteTxt

This commit is contained in:
Jesse-Ma
2023-03-01 17:10:16 +08:00
parent aa3315a909
commit 3f197dde05
7 changed files with 114 additions and 42 deletions

View File

@@ -0,0 +1,39 @@
package com.flagnote.note.utils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(RuntimeException.class)
public Object businessExceptionHandler(HttpServletRequest request,HttpServletResponse response,Exception e)
{
log.error("ExceptionHandler(RuntimeException.class)",e);
JsonResult jsonResult = new JsonResult();
String message = e.getMessage();
if (null!=message && message.matches("^E:\\d{6}$")) {
jsonResult.setCode(message.substring(2, 8));
}else {
jsonResult.setCode("800000");
}
jsonResult.setMessage("business exception");
return jsonResult;
}
@ExceptionHandler(Exception.class)
public Object exceptionHandler(HttpServletRequest request,HttpServletResponse response,Exception e)
{
log.error("ExceptionHandler(Exception.class)",e);
JsonResult jsonResult = new JsonResult();
jsonResult.setCode("900000");
jsonResult.setMessage("exception");
return jsonResult;
}
}