public static ResponseEntity handleException()

in services/library/src/main/java/com/google/cloud/pso/bq_pii_classifier/helpers/ControllerExceptionHelper.java [134:164]


    public static ResponseEntity handleException(Exception ex, LoggingHelper logger, String trackingId){

        ThrowableInfo exInfo = causedByRetryableException(ex);

        if(exInfo.isRetryable()){
            logger.logRetryableExceptions(trackingId, ex, exInfo.getNotes());
            return new ResponseEntity(ex.getMessage(), HttpStatus.TOO_MANY_REQUESTS);

        }else{

            // Debug BigQuery exceptions in more details
            Class exceptionClass = ex.getClass();
            if(BigQueryException.class.isAssignableFrom(exceptionClass)){
                BigQueryException bigQueryException = (BigQueryException) ex;
                // when hitting the concurrent interactive queries
                String msg = String.format("BigQuery Exception: msg: %s - reason: %s - code: %s - isRetryable: %s - full exception: %s",
                        bigQueryException.getMessage(),
                        bigQueryException.getReason() != null? bigQueryException.getReason() : "<NULL Reason>",
                        bigQueryException.getCode(),
                        bigQueryException.isRetryable(),
                        bigQueryException.toString()
                        );
                logger.logDebugWithTracker(trackingId, msg);
            }

            // if not, log and ACK so that it's not retried
            ex.printStackTrace();
            logger.logNonRetryableExceptions(trackingId, ex);
            return new ResponseEntity(ex.getMessage(), HttpStatus.OK);
        }
    }