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.core.exception;
17
18 import software.amazon.awssdk.annotations.SdkPublicApi;
19
20 /**
21  * Base type for all client exceptions thrown by the SDK.
22  *
23  * This exception is thrown when service could not be contacted for a response,
24  * or when client is unable to parse the response from service.
25  *
26  * All exceptions that extend {@link SdkClientException} are assumed to be
27  * not retryable.
28  *
29  * @see SdkServiceException
30  */

31 @SdkPublicApi
32 public class SdkClientException extends SdkException {
33
34     protected SdkClientException(Builder b) {
35         super(b);
36     }
37
38     public static SdkClientException create(String message) {
39         return SdkClientException.builder().message(message).build();
40     }
41
42     public static SdkClientException create(String message, Throwable cause) {
43         return SdkClientException.builder().message(message).cause(cause).build();
44     }
45
46     /**
47      * Create a {@link Builder} initialized with the properties of this {@code SdkClientException}.
48      *
49      * @return A new builder initialized with this config's properties.
50      */

51     @Override
52     public Builder toBuilder() {
53         return new BuilderImpl(this);
54     }
55
56     /**
57      * @return {@link Builder} instance to construct a new {@link SdkClientException}.
58      */

59     public static Builder builder() {
60         return new BuilderImpl();
61     }
62
63     public interface Builder extends SdkException.Builder {
64
65         @Override
66         Builder message(String message);
67
68         @Override
69         Builder cause(Throwable cause);
70
71         @Override
72         SdkClientException build();
73     }
74
75     protected static class BuilderImpl extends SdkException.BuilderImpl implements Builder {
76
77         protected BuilderImpl() {
78         }
79
80         protected BuilderImpl(SdkClientException ex) {
81             super(ex);
82         }
83
84         @Override
85         public Builder message(String message) {
86             this.message = message;
87             return this;
88         }
89
90         @Override
91         public Builder cause(Throwable cause) {
92             this.cause = cause;
93             return this;
94         }
95
96         @Override
97         public SdkClientException build() {
98             return new SdkClientException(this);
99         }
100     }
101 }
102