33import java .lang .ref .WeakReference ;
44import java .net .URI ;
55import java .time .Duration ;
6- import java .util .ArrayList ;
7- import java .util .List ;
8- import java .util .concurrent .BlockingQueue ;
96import java .util .concurrent .CompletableFuture ;
107import java .util .concurrent .ConcurrentHashMap ;
11- import java .util .concurrent .LinkedBlockingQueue ;
128import java .util .concurrent .TimeUnit ;
139
1410import com .github .benmanes .caffeine .cache .Cache ;
1511import com .github .benmanes .caffeine .cache .Caffeine ;
1612
1713import arc .util .Http ;
1814import arc .util .Http .HttpRequest ;
15+ import arc .util .Http .HttpStatusException ;
1916import arc .util .Log ;
2017import arc .util .Strings ;
2118import mindustrytool .utils .JsonUtils ;
2219import mindustrytool .utils .Utils ;
2320import mindustrytool .ServerController ;
24- import mindustrytool .type .BuildLogDto ;
2521import mindustrytool .type .MindustryPlayerDto ;
2622import mindustrytool .type .PaginationRequest ;
2723import mindustrytool .type .PlayerDto ;
2824import mindustrytool .type .ServerDto ;
2925
3026public class ApiGateway {
3127
32- private final WeakReference <ServerController > context ;
28+ final WeakReference <ServerController > context ;
3329 private final ConcurrentHashMap <String , Object > locks = new ConcurrentHashMap <>();
3430
3531 public Cache <PaginationRequest , ServerDto > serverQueryCache = Caffeine .newBuilder ()
@@ -83,7 +79,15 @@ private <T> T send(HttpRequest req, int timeout, Class<T> clazz) {
8379 .header ("X-SERVER-ID" , ServerController .SERVER_ID .toString ())
8480 .timeout (timeout * 1000 )
8581 .redirects (true )
86- .error (error -> res .completeExceptionally (new RuntimeException (req .url , error )))
82+ .error (error -> {
83+ if (error instanceof HttpStatusException ) {
84+ HttpStatusException e = (HttpStatusException ) error ;
85+ res .completeExceptionally (
86+ new RuntimeException (req .url + " " + e .response .getResultAsString (), e ));
87+ } else {
88+ res .completeExceptionally (new RuntimeException (req .url , error ));
89+ }
90+ })
8791 .submit (response -> {
8892 try {
8993 if (clazz .equals (Void .class )) {
@@ -106,7 +110,7 @@ private <T> T send(HttpRequest req, int timeout, Class<T> clazz) {
106110 try {
107111 return res .get (timeout , TimeUnit .SECONDS );
108112 } catch (Throwable e ) {
109- throw new RuntimeException (req .method + " " + req .url , e );
113+ throw new RuntimeException (req .method + " " + req .url , e );
110114 }
111115 }
112116
0 commit comments