All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.duracloud.syncui.controller.SyncControllerAdvice Maven / Gradle / Ivy

There is a newer version: 8.1.0
Show newest version
/*
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 *     http://duracloud.org/license/
 */
package org.duracloud.syncui.controller;

import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * Adds a global exception handler for all controllers.
 * @author Daniel Bernstein
 *
 */
@ControllerAdvice
public class SyncControllerAdvice {
    @ExceptionHandler(Throwable.class)
    public ModelAndView handleException(Throwable t){
        ModelAndView mav = new ModelAndView("exception");
        t.fillInStackTrace();
        mav.addObject("message", t.getMessage());
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        PrintWriter write = new PrintWriter(os);
        t.printStackTrace(write);
        write.close();
        
        mav.addObject("stackTrace", new String(os.toByteArray()));
        return mav;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy