-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
64 additions
and
33 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
tomcat/src/main/java/org/apache/coyote/http11/ExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.apache.coyote.http11; | ||
|
||
import static org.apache.coyote.http11.ContentType.TEXT_HTML; | ||
|
||
import java.io.IOException; | ||
|
||
public class ExceptionHandler { | ||
|
||
private static final String RESOURCE_PATH_FORMAT = "static/%s.html"; | ||
|
||
public HttpResponse handleException(HttpException e) throws IOException { | ||
HttpStatus httpStatus = e.httpStatus(); | ||
int code = httpStatus.statusCode(); | ||
ResourceLoader resourceLoader = new ResourceLoader(); | ||
String body = resourceLoader.loadResourceAsString(String.format(RESOURCE_PATH_FORMAT, code)); | ||
return HttpResponse.from(httpStatus, TEXT_HTML, body); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
tomcat/src/main/java/org/apache/coyote/http11/HttpException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.apache.coyote.http11; | ||
|
||
public class HttpException extends RuntimeException { | ||
|
||
private final HttpStatus httpStatus; | ||
|
||
public HttpException(HttpStatus httpStatus, String message) { | ||
super(message); | ||
this.httpStatus = httpStatus; | ||
} | ||
|
||
public HttpStatus httpStatus() { | ||
return httpStatus; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters