1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  *  http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */

15
16 package software.amazon.awssdk.protocols.core;
17
18 import java.util.function.Supplier;
19 import software.amazon.awssdk.annotations.SdkProtectedApi;
20 import software.amazon.awssdk.core.SdkPojo;
21
22 /**
23  * Metadata needed to unmarshall a modeled exception.
24  */

25 @SdkProtectedApi
26 public final class ExceptionMetadata {
27
28     private final String errorCode;
29     private final Supplier<SdkPojo> exceptionBuilderSupplier;
30     private final Integer httpStatusCode;
31
32     private ExceptionMetadata(Builder builder) {
33         this.errorCode = builder.errorCode;
34         this.exceptionBuilderSupplier = builder.exceptionBuilderSupplier;
35         this.httpStatusCode = builder.httpStatusCode;
36     }
37
38     /**
39      * Returns the error code for the modeled exception.
40      */

41     public String errorCode() {
42         return errorCode;
43     }
44
45     /**
46      * Returns the Supplier to get the builder class for the exception.
47      */

48     public Supplier<SdkPojo> exceptionBuilderSupplier() {
49         return exceptionBuilderSupplier;
50     }
51
52     /**
53      * Returns the http status code for the exception.
54      * For modeled exceptions, this value is populated from the c2j model.
55      */

56     public Integer httpStatusCode() {
57         return httpStatusCode;
58     }
59
60     public static Builder builder() {
61         return new Builder();
62     }
63
64     /**
65      * Builder for {@link ExceptionMetadata}
66      */

67     public static final class Builder {
68         private String errorCode;
69         private Supplier<SdkPojo> exceptionBuilderSupplier;
70         private Integer httpStatusCode;
71
72         private Builder() {
73         }
74
75         public Builder errorCode(String errorCode) {
76             this.errorCode = errorCode;
77             return this;
78         }
79
80         public Builder exceptionBuilderSupplier(Supplier<SdkPojo> exceptionBuilderSupplier) {
81             this.exceptionBuilderSupplier = exceptionBuilderSupplier;
82             return this;
83         }
84
85         public Builder httpStatusCode(Integer httpStatusCode) {
86             this.httpStatusCode = httpStatusCode;
87             return this;
88         }
89
90         public ExceptionMetadata build() {
91             return new ExceptionMetadata(this);
92         }
93     }
94 }
95