Skip to content

Commit 551a5cb

Browse files
SentryManrbygrave
andauthored
Fix error handler controllers failing test-compilation (#593)
Co-authored-by: Rob Bygrave <robin.bygrave@gmail.com>
1 parent 940857d commit 551a5cb

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

http-generator-core/src/main/java/io/avaje/http/generator/core/BaseProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ private void writeClientAdapter(ControllerReader reader) {
187187

188188
try {
189189
if (reader.beanType().getInterfaces().isEmpty()
190-
&& "java.lang.Object".equals(reader.beanType().getSuperclass().toString())) {
191-
new TestClientWriter(reader).write();
190+
&& "java.lang.Object".equals(reader.beanType().getSuperclass().toString())
191+
&& new TestClientWriter(reader).write()) {
192192
clientFQNs.add(reader.beanType().getQualifiedName().toString() + "TestAPI");
193193
}
194194
} catch (final IOException e) {

http-generator-core/src/main/java/io/avaje/http/generator/core/TestClientWriter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ protected String initPackageName(String originName) {
5454
return dp > -1 ? originName.substring(0, dp) : null;
5555
}
5656

57-
void write() {
58-
if (methods.isEmpty()) return;
57+
boolean write() {
58+
if (methods.isEmpty()) return false;
5959
writePackage();
6060
writeImports();
6161
writeClassStart();
6262
writeAddRoutes();
63+
return true;
6364
}
6465

6566
protected void writePackage() {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.example.web;
2+
3+
import io.avaje.http.api.Controller;
4+
import io.avaje.http.api.ExceptionHandler;
5+
import io.avaje.http.api.Filter;
6+
import io.avaje.http.api.Produces;
7+
import io.avaje.jex.http.Context;
8+
import io.avaje.jex.http.HttpFilter.FilterChain;
9+
10+
@Controller
11+
public class ErrorController {
12+
13+
@Filter
14+
void filter(FilterChain chain) {
15+
// do nothing
16+
chain.proceed();
17+
}
18+
19+
@ExceptionHandler
20+
String exception(RuntimeException ex) {
21+
return "Err: " + ex;
22+
}
23+
24+
@Produces(statusCode = 501)
25+
@ExceptionHandler
26+
HelloDto exceptionCtx(IllegalAccessException ex, Context ctx) {
27+
return null;
28+
}
29+
}

0 commit comments

Comments
 (0)