-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from scireum/jvo/issue_123
Standard-Compliant Error Messages
- Loading branch information
Showing
9 changed files
with
205 additions
and
42 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Made with all the love in the world | ||
* by scireum in Remshalden, Germany | ||
* | ||
* Copyright by scireum GmbH | ||
* http://www.scireum.de - [email protected] | ||
*/ | ||
|
||
package ninja.errors; | ||
|
||
import io.netty.handler.codec.http.HttpResponseStatus; | ||
|
||
/** | ||
* Lists some <em>S3</em> <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html">error codes</a> | ||
* along with their respective {@linkplain HttpResponseStatus HTTP response codes}. | ||
*/ | ||
public enum S3ErrorCode { | ||
AccessDenied(HttpResponseStatus.FORBIDDEN), | ||
BadDigest(HttpResponseStatus.BAD_REQUEST), | ||
IncompleteBody(HttpResponseStatus.BAD_REQUEST), | ||
InternalError(HttpResponseStatus.INTERNAL_SERVER_ERROR), | ||
InvalidDigest(HttpResponseStatus.BAD_REQUEST), | ||
InvalidRequest(HttpResponseStatus.BAD_REQUEST), | ||
NoSuchBucket(HttpResponseStatus.NOT_FOUND), | ||
NoSuchBucketPolicy(HttpResponseStatus.NOT_FOUND), | ||
NoSuchKey(HttpResponseStatus.NOT_FOUND), | ||
NoSuchLifecycleConfiguration(HttpResponseStatus.NOT_FOUND), | ||
NoSuchUpload(HttpResponseStatus.NOT_FOUND); | ||
|
||
private final HttpResponseStatus httpStatusCode; | ||
|
||
S3ErrorCode(HttpResponseStatus httpStatusCode) { | ||
this.httpStatusCode = httpStatusCode; | ||
} | ||
|
||
public HttpResponseStatus getHttpStatusCode() { | ||
return httpStatusCode; | ||
} | ||
} |
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,58 @@ | ||
/* | ||
* Made with all the love in the world | ||
* by scireum in Remshalden, Germany | ||
* | ||
* Copyright by scireum GmbH | ||
* http://www.scireum.de - [email protected] | ||
*/ | ||
|
||
package ninja.errors; | ||
|
||
import sirius.kernel.commons.Strings; | ||
import sirius.kernel.di.std.Register; | ||
import sirius.kernel.xml.XMLStructuredOutput; | ||
import sirius.web.http.WebContext; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Synthesizes <em>S3</em> <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html">error | ||
* responses</a>. | ||
*/ | ||
@Register(classes = S3ErrorSynthesizer.class) | ||
public class S3ErrorSynthesizer { | ||
|
||
/** | ||
* Synthesizes an error response. | ||
* | ||
* @param ctx the request to process. | ||
* @param bucket the requested bucket, potentially <b>null</b>. | ||
* @param key the requested object's key, potentially <b>null</b>. | ||
* @param code the error code to send. | ||
* @param message a human-readable description of the error. | ||
*/ | ||
public void synthesiseError(@Nonnull WebContext ctx, | ||
@Nullable String bucket, | ||
@Nullable String key, | ||
@Nonnull S3ErrorCode code, | ||
@Nullable String message) { | ||
XMLStructuredOutput | ||
xml = new XMLStructuredOutput(ctx.respondWith() | ||
.outputStream(code.getHttpStatusCode(), "text/xml")); | ||
|
||
String resource = null; | ||
if (Strings.isFilled(bucket)) { | ||
resource = "/" + bucket; | ||
if (Strings.isFilled(key)) { | ||
resource += "/" + key; | ||
} | ||
} | ||
|
||
xml.beginOutput("Error"); | ||
xml.property("Code", code.toString()); | ||
xml.propertyIfFilled("Message", message); | ||
xml.propertyIfFilled("Resource", resource); | ||
xml.endOutput(); | ||
} | ||
} |
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
Oops, something went wrong.