Skip to content

Commit 58ed0e4

Browse files
author
Pritham Marupaka
committed
Use SerailizableErrorProvider
1 parent b13b56d commit 58ed0e4

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

conjure-java-core/src/main/java/com/palantir/conjure/java/types/ErrorGenerator.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.palantir.conjure.java.api.errors.ErrorType;
2828
import com.palantir.conjure.java.api.errors.RemoteException;
2929
import com.palantir.conjure.java.api.errors.SerializableError;
30+
import com.palantir.conjure.java.api.errors.SerializableErrorProvider;
3031
import com.palantir.conjure.java.api.errors.ServiceException;
3132
import com.palantir.conjure.java.util.ErrorGenerationUtils;
3233
import com.palantir.conjure.java.util.ErrorGenerationUtils.DeclaredEndpointErrors;
@@ -164,7 +165,8 @@ private JavaFile generateErrorTypesForNamespace(
164165
})
165166
.collect(Collectors.toList());
166167

167-
TypeSpec.Builder typeBuilder = TypeSpec.classBuilder(errorTypesClassName(conjurePackage, namespace))
168+
ClassName errorsClassName = errorTypesClassName(conjurePackage, namespace);
169+
TypeSpec.Builder typeBuilder = TypeSpec.classBuilder(errorsClassName)
168170
.addMethod(ErrorGenerationUtils.privateConstructor())
169171
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
170172
.addFields(generateErrorTypeFields(namespace, errorTypeDefinitions))
@@ -176,7 +178,7 @@ private JavaFile generateErrorTypesForNamespace(
176178
typeBuilder
177179
.addTypes(generateErrorParameterRecords(errorTypeDefinitions, typeMapper))
178180
.addTypes(generateSerializableErrors(errorTypeDefinitions))
179-
.addTypes(generateRemoteExceptionTypes(errorTypeDefinitions));
181+
.addTypes(generateRemoteExceptionTypes(errorsClassName, errorTypeDefinitions));
180182
}
181183

182184
return JavaFile.builder(conjurePackage, typeBuilder.build())
@@ -185,20 +187,25 @@ private JavaFile generateErrorTypesForNamespace(
185187
.build();
186188
}
187189

188-
private static List<TypeSpec> generateRemoteExceptionTypes(List<ErrorDefinition> errorDefinitions) {
190+
private static List<TypeSpec> generateRemoteExceptionTypes(
191+
ClassName errorsClassName, List<ErrorDefinition> errorDefinitions) {
189192
return errorDefinitions.stream()
190-
.map(ErrorGenerator::generateRemoteExceptionType)
193+
.map(def -> generateRemoteExceptionType(errorsClassName, def))
191194
.toList();
192195
}
193196

194-
private static TypeSpec generateRemoteExceptionType(ErrorDefinition errorDefinition) {
197+
private static TypeSpec generateRemoteExceptionType(ClassName errorsClassName, ErrorDefinition errorDefinition) {
195198
String remoteExceptionClassName = errorDefinition.getErrorName().getName() + "Exception";
196199
ClassName serializableErrorClassName =
197-
ClassName.get("", errorDefinition.getErrorName().getName() + "SerializableError");
200+
errorsClassName.nestedClass(errorDefinition.getErrorName().getName() + "SerializableError");
198201

199202
TypeSpec.Builder classBuilder = TypeSpec.classBuilder(remoteExceptionClassName)
200203
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
201204
.superclass(RemoteException.class)
205+
.addSuperinterface(ParameterizedTypeName.get(
206+
ClassName.get(SerializableErrorProvider.class),
207+
errorsClassName.nestedClass(ErrorGenerationUtils.errorParametersClassName(
208+
errorDefinition.getErrorName().getName()))))
202209
.addField(FieldSpec.builder(serializableErrorClassName, "error")
203210
.addModifiers(Modifier.PRIVATE)
204211
.build())

versions.lock

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ com.palantir.conjure:conjure-api-objects:4.50.0 (3 constraints: 9327531f)
4444

4545
com.palantir.conjure:conjure-generator-common:4.50.0 (2 constraints: fd13a782)
4646

47-
com.palantir.conjure.java.api:errors:2.64.0 (8 constraints: a394547a)
47+
com.palantir.conjure.java.api:errors:2.64.0-4-g1d1a7d0 (8 constraints: 42a0682a)
4848

49-
com.palantir.conjure.java.api:service-config:2.64.0 (6 constraints: 37668fd8)
49+
com.palantir.conjure.java.api:service-config:2.64.0-4-g1d1a7d0 (6 constraints: ef6e261e)
5050

51-
com.palantir.conjure.java.api:ssl-config:2.64.0 (5 constraints: b54faa2d)
51+
com.palantir.conjure.java.api:ssl-config:2.64.0-4-g1d1a7d0 (5 constraints: 84558bae)
5252

5353
com.palantir.conjure.java.runtime:client-config:8.24.0 (6 constraints: ae6b4e29)
5454

@@ -60,19 +60,19 @@ com.palantir.conjure.java.runtime:keystores:8.24.0 (3 constraints: 172ac85d)
6060

6161
com.palantir.deadlines:deadlines:0.15.0 (2 constraints: 9f1404ac)
6262

63-
com.palantir.dialogue:dialogue-apache-hc5-client:6.8.0-7-gde83dba (2 constraints: 6e2cef8c)
63+
com.palantir.dialogue:dialogue-apache-hc5-client:6.8.0-22-g9d026eb (2 constraints: 3c2c49b6)
6464

65-
com.palantir.dialogue:dialogue-blocking-channels:6.8.0-7-gde83dba (2 constraints: 212a62b2)
65+
com.palantir.dialogue:dialogue-blocking-channels:6.8.0-22-g9d026eb (2 constraints: bd295ee2)
6666

67-
com.palantir.dialogue:dialogue-clients:6.8.0-7-gde83dba (1 constraints: 63080280)
67+
com.palantir.dialogue:dialogue-clients:6.8.0-22-g9d026eb (1 constraints: 31085185)
6868

69-
com.palantir.dialogue:dialogue-core:6.8.0-7-gde83dba (3 constraints: 924385ad)
69+
com.palantir.dialogue:dialogue-core:6.8.0-22-g9d026eb (3 constraints: 2e432f0f)
7070

71-
com.palantir.dialogue:dialogue-futures:6.8.0-7-gde83dba (3 constraints: 3a3d7f36)
71+
com.palantir.dialogue:dialogue-futures:6.8.0-22-g9d026eb (3 constraints: a43c338b)
7272

73-
com.palantir.dialogue:dialogue-serde:6.8.0-7-gde83dba (3 constraints: d034782d)
73+
com.palantir.dialogue:dialogue-serde:6.8.0-22-g9d026eb (3 constraints: 6c34b54b)
7474

75-
com.palantir.dialogue:dialogue-target:6.8.0-7-gde83dba (7 constraints: c98b0624)
75+
com.palantir.dialogue:dialogue-target:6.8.0-22-g9d026eb (7 constraints: 9d8a2158)
7676

7777
com.palantir.goethe:goethe:0.16.0 (1 constraints: 3905353b)
7878

@@ -124,7 +124,7 @@ com.squareup:javapoet:1.13.0 (1 constraints: f50b65f7)
124124

125125
info.picocli:picocli:4.7.7 (1 constraints: 14051b36)
126126

127-
io.dropwizard.metrics:metrics-core:4.2.34 (28 constraints: f8e6781b)
127+
io.dropwizard.metrics:metrics-core:4.2.36 (28 constraints: fee68031)
128128

129129
io.smallrye.common:smallrye-common-constraint:2.4.0 (3 constraints: c633ce60)
130130

@@ -154,7 +154,7 @@ org.apache.commons:commons-lang3:3.18.0 (3 constraints: fe2123fa)
154154

155155
org.apache.httpcomponents.client5:httpclient5:5.4.3 (3 constraints: f43937e8)
156156

157-
org.apache.httpcomponents.core5:httpcore5:5.3.4 (4 constraints: 034863a7)
157+
org.apache.httpcomponents.core5:httpcore5:5.3.5 (4 constraints: 0448f8a7)
158158

159159
org.apache.httpcomponents.core5:httpcore5-h2:5.3.4 (1 constraints: 4013103c)
160160

@@ -240,7 +240,7 @@ com.netflix.feign:feign-jackson:8.18.0 (1 constraints: c718909e)
240240

241241
com.palantir.conjure:conjure-core:4.50.0 (1 constraints: 3b054b3b)
242242

243-
com.palantir.conjure.java.api:test-utils:2.64.0 (1 constraints: 3e054f3b)
243+
com.palantir.conjure.java.api:test-utils:2.64.0-4-g1d1a7d0 (1 constraints: 3e054f3b)
244244

245245
com.palantir.conjure.java.runtime:conjure-java-annotations:8.24.0 (1 constraints: c418889e)
246246

versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ com.palantir.conjure.java.runtime:* = 8.24.0
1111
com.palantir.conjure.verification:* = 0.19.0
1212
com.palantir.conjure:* = 4.50.0
1313
com.palantir.deadlines:* = 0.15.0
14-
com.palantir.dialogue:* = 6.8.0-7-gde83dba
14+
com.palantir.dialogue:* = 6.8.0-22-g9d026eb
1515
com.palantir.goethe:* = 0.16.0
1616
com.palantir.human-readable-types:* = 1.7.0
1717
com.palantir.javapoet:javapoet = 0.7.0

0 commit comments

Comments
 (0)