@@ -18,20 +18,22 @@ public static CastleRuntimeException handle(IOException e) {
1818
1919 public static void handle (Response response ) throws CastleServerErrorException {
2020 if (!response .isSuccessful () && !response .isRedirect ()) {
21- if (response .code () == 500 ) {
22- throw new CastleApiInternalServerErrorException ( response );
23- }
24- if ( response . code () == 422 ) {
25- try {
26- String body = response .peekBody (Long .MAX_VALUE ).string ();
27- JsonObject json = (JsonObject ) JsonParser .parseString (body );
28- String type = json .get ("type" ).getAsString ();
21+ switch (response .code ()) {
22+ case 500 :
23+ throw new CastleApiInternalServerErrorException ( response );
24+ case 422 :
25+ try {
26+ String body = response .peekBody (Long .MAX_VALUE ).string ();
27+ JsonObject json = (JsonObject ) JsonParser .parseString (body );
28+ String type = json .get ("type" ).getAsString ();
2929
30- if (type .equals ("invalid_request_token" )) {
31- throw new CastleApiInvalidRequestTokenException (response );
32- }
33- } catch (IOException | JsonSyntaxException | JsonIOException | IllegalStateException ignored ) {}
34- throw new CastleApiInvalidParametersException (response );
30+ if (type .equals ("invalid_request_token" )) {
31+ throw new CastleApiInvalidRequestTokenException (response );
32+ }
33+ } catch (IOException | JsonSyntaxException | JsonIOException | IllegalStateException ignored ) {}
34+ throw new CastleApiInvalidParametersException (response );
35+ case 404 :
36+ throw new CastleApiNotFoundException (response );
3537 }
3638 throw new CastleServerErrorException (response );
3739 }
0 commit comments