Giter VIP home page Giter VIP logo

uups's Introduction

Uups!

Pretty error page for Java Web apps (Spring Boot, Javalin, ...) that helps you debug your web application in the browser. Because stacktraces can be hard to read in the console!

  • See request parameters, headers, route, session and response status
  • Full Stacktrace
  • Source Code preview
  • Open file in IntelliJ IDEA exactly where the exception was thrown

image

Dependency

Maven

<dependency>
    <groupId>com.github.jstumpp</groupId>
    <artifactId>uups</artifactId>
    <version>0.1.1</version>
</dependency>

Gradle

compile('com.github.jstumpp:uups:0.1.1')

Usage

With a servlet engine, e.g. Javalin

Javalin app = Javalin.create().start();

app.exception(Exception.class, (e, ctx) -> {
    ctx.html(Uups.renderHtml(e, ctx.status(), ctx.method(), ctx.path(), ctx.req));
});

With Spring boot

To utilize, implement an ErrorController in your project:

import com.github.jstumpp.uups.Uups;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ErrorAttributes;
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
public class DefaultErrorController implements ErrorController {

    private static final String PATH = "/error";

    @Autowired
    private ErrorAttributes errorAttributes;

    @RequestMapping(value = PATH)
    public String error(HttpServletRequest request, HttpServletResponse response) {
        RequestAttributes requestAttributes = new ServletRequestAttributes(request);
        Throwable cause = errorAttributes.getError(requestAttributes);
        Map errorAtt = errorAttributes.getErrorAttributes(requestAttributes, false);
        return Uups.renderHtml(cause, response.getStatus(), request.getMethod(), errorAtt.get("path").toString(), request);
    }

    @Override
    public String getErrorPath() {
        return PATH;
    }
}

Notes:

  • This handler reveals server internals and possibly code. Only install it when you are developing and make sure to disable it before pushing to production.
  • Finding code snippets is an imperfect art since the original file locations are not preserved in the compiled bytecode. Thus, by default code snippets will only be displayed if the Java source file for the corresponding exception stack frame is available within the working directory under src/main/java or src/main/test and you are properly following the Java naming and directory structure conventions.

Credits:

Based on jooby/whoops and filp/whoops.

uups's People

Contributors

jstumpp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

pydawan calevin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.