Skip to content

Commit

Permalink
#5 show nicer stacktrace page
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed Apr 1, 2016
1 parent 8fc430c commit a61429d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
29 changes: 28 additions & 1 deletion src/main/java/io/jare/tk/TkApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.takes.Take;
import org.takes.facets.auth.TkSecure;
import org.takes.facets.fallback.TkFallback;
import org.takes.facets.flash.TkFlash;
import org.takes.facets.fork.FkAuthenticated;
import org.takes.facets.fork.FkFixed;
Expand All @@ -38,6 +40,10 @@
import org.takes.facets.fork.FkRegex;
import org.takes.facets.fork.TkFork;
import org.takes.facets.forward.TkForward;
import org.takes.misc.Opt;
import org.takes.rs.RsWithBody;
import org.takes.rs.RsWithStatus;
import org.takes.rs.RsWithType;
import org.takes.tk.TkClasspath;
import org.takes.tk.TkFiles;
import org.takes.tk.TkGzip;
Expand All @@ -57,6 +63,7 @@
* @checkstyle MultipleStringLiteralsCheck (500 lines)
* @checkstyle ClassFanOutComplexityCheck (500 lines)
*/
@SuppressWarnings("PMD.ExcessiveImports")
public final class TkApp extends TkWrap {

/**
Expand Down Expand Up @@ -116,7 +123,27 @@ private static Take make(final Base base) throws IOException {
*/
private static Take regex(final Base base) throws IOException {
return new TkFork(
new FkHost("relay.jare.io", new TkRelay(base)),
new FkHost(
"relay.jare.io",
new TkFallback(
new TkRelay(base),
req -> new Opt.Single<>(
new RsWithType(
new RsWithBody(
new RsWithStatus(req.code()),
String.format(
// @checkstyle LineLength (1 line)
"Please, submit this stacktrace to GitHub and we'll try to help: https://github.com/yegor256/jare/issues\n\n%s",
ExceptionUtils.getStackTrace(
req.throwable()
)
)
),
"text/plain"
)
)
)
),
new FkRegex("/robots.txt", ""),
new FkRegex(
"/xsl/[a-z\\-]+\\.xsl",
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/jare/tk/TkRelay.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private String path(final URI uri) throws HttpException {
final Iterator<Domain> domains = this.base.domain(host);
if (!domains.hasNext()) {
throw new HttpException(
HttpURLConnection.HTTP_NOT_FOUND,
HttpURLConnection.HTTP_BAD_REQUEST,
String.format("domain \"%s\" is not registered", host)
);
}
Expand Down

0 comments on commit a61429d

Please sign in to comment.