Commit f8ae5a5c by 吴迪

【修改】异常处理

parent 8664e7d7
...@@ -58,15 +58,12 @@ public class RRExceptionHandler { ...@@ -58,15 +58,12 @@ public class RRExceptionHandler {
return R.error(); return R.error();
} }
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
public R handleException(Exception e){ public R handleException(Exception e){
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
return R.error(); return R.error();
} }
@ExceptionHandler(IllegalArgumentException.class)
public R handleException(IllegalArgumentException e){
logger.error(e.getMessage(), e);
return R.error();
}
} }
package io.office.modules.manage.controller; package io.office.modules.manage.controller;
import com.github.mbhk.barcode4j.Configuration; import com.github.mbhk.barcode4j.Configuration;
import io.office.common.exception.RRException;
import io.office.modules.app.annotation.Login; import io.office.modules.app.annotation.Login;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.krysalis.barcode4j.BarcodeException; import org.krysalis.barcode4j.BarcodeException;
...@@ -33,12 +35,10 @@ import java.util.logging.Logger; ...@@ -33,12 +35,10 @@ import java.util.logging.Logger;
*/ */
@RestController @RestController
@RequestMapping("/barcodegeneration") @RequestMapping("/barcodegeneration")
@Slf4j
public class BarcodeController { public class BarcodeController {
private final Log logger = LogFactory.getLog(getClass());
public Log getLogger() {
return logger;
}
/** Parameter name for the message */ /** Parameter name for the message */
public static final String BARCODE_MSG = "msg"; public static final String BARCODE_MSG = "msg";
/** Parameter name for the barcode type */ /** Parameter name for the barcode type */
...@@ -68,11 +68,11 @@ public class BarcodeController { ...@@ -68,11 +68,11 @@ public class BarcodeController {
private static final String ERROR_WHILE_GENERATING_BARCODE = "Error while generating barcode"; private static final String ERROR_WHILE_GENERATING_BARCODE = "Error while generating barcode";
private static final Logger LOGGER = Logger.getLogger(BarcodeController.class.getName());
@Login @Login
@GetMapping(value="/api/gensvg") @GetMapping(value="/api/gensvg")
public void getBarcode(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { public void getBarcode(HttpServletRequest request, HttpServletResponse response) {
try { try {
System.out.println("barcode................"); System.out.println("barcode................");
final String format = determineFormat(request); final String format = determineFormat(request);
...@@ -140,17 +140,17 @@ public class BarcodeController { ...@@ -140,17 +140,17 @@ public class BarcodeController {
response.getOutputStream().write(bout.toByteArray()); response.getOutputStream().write(bout.toByteArray());
response.getOutputStream().flush(); response.getOutputStream().flush();
} catch (BarcodeException e) { } catch (BarcodeException e) {
LOGGER.log(Level.SEVERE, ERROR_WHILE_GENERATING_BARCODE, e); log.error(ERROR_WHILE_GENERATING_BARCODE, e);
throw new ServletException(e); throw new RRException(e.getMessage());
} catch (TransformerException e) { } catch (TransformerException e) {
LOGGER.log(Level.SEVERE, ERROR_WHILE_GENERATING_BARCODE, e); log.error(ERROR_WHILE_GENERATING_BARCODE, e);
throw new ServletException(e); throw new RRException(e.getMessage());
} catch (IOException e) { } catch (IOException e) {
LOGGER.log(Level.SEVERE, ERROR_WHILE_GENERATING_BARCODE, e); log.error(ERROR_WHILE_GENERATING_BARCODE, e);
throw new ServletException(e); throw new RRException(e.getMessage());
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
LOGGER.log(Level.SEVERE, ERROR_WHILE_GENERATING_BARCODE, e); log.error( ERROR_WHILE_GENERATING_BARCODE, e);
throw new ServletException(e); throw new RRException(e.getMessage());
} }
} }
......
...@@ -63,8 +63,6 @@ public class BarcodeGenerationServiceImpl implements BarcodeGenerationService { ...@@ -63,8 +63,6 @@ public class BarcodeGenerationServiceImpl implements BarcodeGenerationService {
}else if(content.length()>48){ }else if(content.length()>48){
throw new RRException("总长度不能超过48位"); throw new RRException("总长度不能超过48位");
} }
String url = ""; String url = "";
if (content.length() > 50) { if (content.length() > 50) {
throw new RRException("最大50位!"); throw new RRException("最大50位!");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment