AnsweredAssumed Answered

Exception  Handling in java service task

Question asked by prash.aggarwal on Sep 6, 2016
Latest reply on Sep 8, 2016 by jbarrez
Hi,

I have a java service task  to check the file type validity, i perform this check and want to throw an exception with message like
"Uploaded file type application/pd not supported"

       if(!fileTypeValid)
          throw new ABCException("Uploaded file type " + fileType +" not supported");

The stack trace i get is
org.activiti.engine.ActivitiException: Error while evaluating expression: ${uploadService.fileTypeValidityCheck(execution)}

Caused by: org.activiti.engine.impl.javax.el.ELException: com.markit.aft.exception.MIMException: Uploaded file type application/pd not supported

Caused by: com.xyz.aft.exception.ABCException: Uploaded file type application/pd not supported

How do i show the original message thrown in the exception ie "Uploaded file type " + fileType +" not supported"

Currently I am doing error.setMessage(e.getCause().getCause().getMessage()); as shown below, is this the right way?
Please guide..

@ExceptionHandler({ActivitiException.class})
    public ResponseEntity<ErrorResponse> handleActivitiException(ActivitiException e){
      ErrorResponse error = new ErrorResponse();
      error.setErrorCode(HttpStatus.BAD_REQUEST.value());
      error.setMessage(e.getCause().getCause().getMessage());
      String errorId = UUID.randomUUID().toString();
      error.setErrorId(errorId);
      LOG.error(error.toString());
      return new ResponseEntity<ErrorResponse>(error, HttpStatus.BAD_REQUEST);
       
    }

Thanks

Outcomes