|
1 | 1 | /* |
2 | | - * Copyright 2022 Conductor Authors. |
| 2 | + * Copyright 2026 Conductor Authors. |
3 | 3 | * <p> |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
5 | 5 | * the License. You may obtain a copy of the License at |
|
15 | 15 | import java.util.List; |
16 | 16 | import java.util.Map; |
17 | 17 |
|
18 | | -import org.apache.commons.lang3.StringUtils; |
| 18 | +import io.orkes.conductor.client.http.ApiException; |
19 | 19 |
|
20 | | -import com.netflix.conductor.common.validation.ValidationError; |
21 | | - |
22 | | -import lombok.Data; |
23 | | -import lombok.Setter; |
24 | | - |
25 | | -@Data |
26 | | -public class ConductorClientException extends RuntimeException { |
27 | | - static boolean initPreferErrOverResponse() { |
28 | | - try { |
29 | | - final String propName = "conductor.client.exception.preferErrOverResponse"; |
30 | | - return Boolean.getBoolean(propName); |
31 | | - } catch (SecurityException e) { |
32 | | - return false; |
33 | | - } |
34 | | - } |
35 | | - |
36 | | - private final static boolean PREFER_ERR_OVER_RESPONSE = initPreferErrOverResponse(); |
37 | | - |
38 | | - private int status; |
39 | | - private String instance; |
40 | | - private String code; |
41 | | - @Setter |
42 | | - private boolean retryable; |
43 | | - private List<ValidationError> validationErrors; //List of validation errors. Available when the status code is 400 |
44 | | - private Map<String, List<String>> responseHeaders; |
45 | | - private String responseBody; |
| 20 | +public class ConductorClientException extends ApiException { |
46 | 21 |
|
47 | 22 | public ConductorClientException(String message) { |
48 | 23 | super(message); |
49 | | - this.responseBody = message; |
50 | 24 | } |
51 | 25 |
|
52 | | - public ConductorClientException(int statusCode, String message) { |
53 | | - super(message); |
54 | | - this.status = statusCode; |
55 | | - this.responseBody = message; |
56 | | - } |
57 | | - |
58 | | - public ConductorClientException(Throwable t) { |
59 | | - super(t.getMessage(), t); |
60 | | - this.responseBody = t.getMessage(); |
| 26 | + public ConductorClientException(String message, int code, Map<String, List<String>> responseHeaders, String responseBody) { |
| 27 | + super(message, code, responseHeaders, responseBody); |
61 | 28 | } |
62 | 29 |
|
63 | 30 | public ConductorClientException(String message, Throwable t) { |
64 | 31 | super(message, t); |
65 | | - this.responseBody = message; |
66 | | - } |
67 | | - |
68 | | - public ConductorClientException(String message, |
69 | | - int code, |
70 | | - Map<String, List<String>> responseHeaders, |
71 | | - String responseBody) { |
72 | | - this(message, null, code, responseHeaders, responseBody); |
73 | | - } |
74 | | - |
75 | | - public ConductorClientException(String message, |
76 | | - Throwable t, |
77 | | - int code, |
78 | | - Map<String, List<String>> responseHeaders) { |
79 | | - this(message, t, code, responseHeaders, message); |
80 | | - } |
81 | | - |
82 | | - public ConductorClientException(String message, |
83 | | - Throwable t, |
84 | | - int code, |
85 | | - Map<String, List<String>> responseHeaders, |
86 | | - String responseBody) { |
87 | | - super(message, t); |
88 | | - this.code = String.valueOf(code); |
89 | | - this.status = code; |
90 | | - this.responseHeaders = responseHeaders; |
91 | | - this.responseBody = responseBody; |
92 | 32 | } |
93 | 33 |
|
94 | | - public boolean isClientError() { |
95 | | - return getStatus() > 399 && getStatus() < 499; |
| 34 | + public ConductorClientException(String message, Throwable t, int code, Map<String, List<String>> responseHeaders) { |
| 35 | + super(message, t, code, responseHeaders); |
96 | 36 | } |
97 | 37 |
|
98 | | - /** |
99 | | - * @return HTTP status code |
100 | | - */ |
101 | | - public int getStatusCode() { |
102 | | - return getStatus(); |
| 38 | + public ConductorClientException(String message, Throwable t, int code, Map<String, List<String>> responseHeaders, String responseBody) { |
| 39 | + super(message, t, code, responseHeaders, responseBody); |
103 | 40 | } |
104 | 41 |
|
105 | | - @Override |
106 | | - public String getMessage() { |
107 | | - if (PREFER_ERR_OVER_RESPONSE) { |
108 | | - return StringUtils.isNotBlank(super.getMessage()) ? super.getMessage() : responseBody; |
109 | | - } |
110 | | - return StringUtils.isNotBlank(responseBody) ? responseBody : super.getMessage(); |
| 42 | + public ConductorClientException(int statusCode, String message) { |
| 43 | + super(statusCode, message); |
111 | 44 | } |
112 | 45 |
|
113 | | - @Override |
114 | | - public String toString() { |
115 | | - StringBuilder builder = new StringBuilder(); |
116 | | - builder.append(getClass().getName()).append(": "); |
117 | | - |
118 | | - if (getMessage() != null) { |
119 | | - builder.append(getMessage()); |
120 | | - } |
121 | | - |
122 | | - if (status > 0) { |
123 | | - builder.append(" {status=").append(status); |
124 | | - if (this.code != null) { |
125 | | - builder.append(", code='").append(code).append("'"); |
126 | | - } |
127 | | - |
128 | | - builder.append(", retryable: ").append(retryable); |
129 | | - } |
130 | | - |
131 | | - if (this.instance != null) { |
132 | | - builder.append(", instance: ").append(instance); |
133 | | - } |
134 | | - |
135 | | - if (this.validationErrors != null) { |
136 | | - builder.append(", validationErrors: ").append(validationErrors); |
137 | | - } |
138 | | - |
139 | | - builder.append("}"); |
140 | | - return builder.toString(); |
| 46 | + public ConductorClientException(Throwable t) { |
| 47 | + super(t); |
141 | 48 | } |
142 | | - |
143 | 49 | } |
0 commit comments