Commit f8ae5a5c by 吴迪

【修改】异常处理

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