From 58ab9c56674c2967b264ab8b3b18336f06c10d66 Mon Sep 17 00:00:00 2001 From: Eric Prud'hommeaux Date: Tue, 7 Dec 2021 23:43:02 +0100 Subject: [PATCH] ~ javatots rewrite catch --- .../client-http/src/HttpResourceAccessor.ts | 28 ++++++++------- .../packages/core/src/ManageableResource.ts | 7 ++-- .../packages/core/src/ResourceAttributes.ts | 2 +- asTypescript/packages/core/src/ShapeTree.ts | 14 ++++---- .../packages/core/src/ShapeTreeAssignment.ts | 9 ++--- .../packages/core/src/ShapeTreeFactory.ts | 21 +++++++----- .../packages/core/src/ShapeTreeManager.ts | 14 ++++---- .../core/src/ShapeTreeManagerDelta.ts | 7 ++-- .../packages/core/src/ShapeTreeReference.ts | 2 +- .../HttpExternalDocumentLoader.ts | 17 +++++----- .../packages/core/src/helpers/GraphHelper.ts | 28 ++++++++------- .../core/src/helpers/RequestHelper.ts | 21 +++++++----- .../packages/javahttp/src/JavaHttpClient.ts | 34 +++++++++++-------- .../javahttp/src/JavaHttpClientFactory.ts | 7 ++-- .../JavaHttpValidatingShapeTreeInterceptor.ts | 22 ++++++------ 15 files changed, 131 insertions(+), 102 deletions(-) diff --git a/asTypescript/packages/client-http/src/HttpResourceAccessor.ts b/asTypescript/packages/client-http/src/HttpResourceAccessor.ts index dfb9f4c6..6135bec9 100644 --- a/asTypescript/packages/client-http/src/HttpResourceAccessor.ts +++ b/asTypescript/packages/client-http/src/HttpResourceAccessor.ts @@ -279,9 +279,10 @@ export class HttpResourceAccessor implements ResourceAccessor { if (location.isPresent()) { try { url = new URL(location.get()); - } catch (e: MalformedURLException) { - throw new ShapeTreeException(500, "Retrieving <" + url + "> yielded a Location header \"" + location.get() + "\" which doesn't parse as a URL: " + e.getMessage()); - } + } catch (ex) { + if (ex instanceof MalformedURLException) { + throw new ShapeTreeException(500, "Retrieving <" + url + "> yielded a Location header \"" + location.get() + "\" which doesn't parse as a URL: " + e.getMessage()); + } } // Determine whether the resource exists based on the response. Even if the resource // doesn't exist, additional context and processing is done to provide the appropriate @@ -350,9 +351,10 @@ export class HttpResourceAccessor implements ResourceAccessor { containedInstances.add(containedInstance); } return containedInstances; - } catch (ex: Exception) { - throw new ShapeTreeException(500, ex.getMessage()); - } + } catch (ex) { + if (ex instanceof Exception) { + throw new ShapeTreeException(500, ex.getMessage()); + } } /** @@ -451,9 +453,10 @@ export class HttpResourceAccessor implements ResourceAccessor { let managerUrlString: string = optManagerString.get(); try { return Optional.of(new URL(url, managerUrlString)); - } catch (e: MalformedURLException) { - throw new ShapeTreeException(500, "Malformed relative URL <" + managerUrlString + "> (resolved from <" + url + ">)"); - } + } catch (ex) { + if (ex instanceof MalformedURLException) { + throw new ShapeTreeException(500, "Malformed relative URL <" + managerUrlString + "> (resolved from <" + url + ">)"); + } } /** @@ -479,9 +482,10 @@ export class HttpResourceAccessor implements ResourceAccessor { } try { managedResourceUrl = new URL(managerUrl, managedUrlString); - } catch (e: MalformedURLException) { - throw new ShapeTreeException(500, "Can't calculate managed resource for shape tree manager <" + managerUrl + ">"); - } + } catch (ex) { + if (ex instanceof MalformedURLException) { + throw new ShapeTreeException(500, "Can't calculate managed resource for shape tree manager <" + managerUrl + ">"); + } return managedResourceUrl; } diff --git a/asTypescript/packages/core/src/ManageableResource.ts b/asTypescript/packages/core/src/ManageableResource.ts index 1d74443d..d87aba13 100644 --- a/asTypescript/packages/core/src/ManageableResource.ts +++ b/asTypescript/packages/core/src/ManageableResource.ts @@ -44,9 +44,10 @@ export class ManageableResource extends InstanceResource { const rel: string = this.isContainer() ? ".." : "."; try { return new URL(this.getUrl(), rel); - } catch (e: MalformedURLException) { - throw new ShapeTreeException(500, "Malformed focus node when resolving <" + rel + "> against <" + this.getUrl() + ">"); - } + } catch (ex) { + if (ex instanceof MalformedURLException) { + throw new ShapeTreeException(500, "Malformed focus node when resolving <" + rel + "> against <" + this.getUrl() + ">"); + } } public getManagerResourceUrl(): URL | null { diff --git a/asTypescript/packages/core/src/ResourceAttributes.ts b/asTypescript/packages/core/src/ResourceAttributes.ts index df2e213c..7f6c85c1 100644 --- a/asTypescript/packages/core/src/ResourceAttributes.ts +++ b/asTypescript/packages/core/src/ResourceAttributes.ts @@ -27,7 +27,7 @@ export class ResourceAttributes { * @param attr attribute (header) name to set * @param value String value to assign to attr */ - public constructor(attr: string, value: string) throws ShapeTreeException { + public constructor(attr: string, value: string) /* throws ShapeTreeException */ { this.myMapOfLists = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); this.maybeSet(attr, value); } diff --git a/asTypescript/packages/core/src/ShapeTree.ts b/asTypescript/packages/core/src/ShapeTree.ts index 5c46f7a7..8d8ddc1e 100644 --- a/asTypescript/packages/core/src/ShapeTree.ts +++ b/asTypescript/packages/core/src/ShapeTree.ts @@ -112,9 +112,10 @@ export class ShapeTree { if (SchemaCache.isInitialized()) { SchemaCache.putSchema(this.shape, schema); } - } catch (ex: Exception) { - throw new ShapeTreeException(500, "Error parsing ShEx schema - " + ex.getMessage()); - } + } catch (ex) { + if (ex instanceof Exception) { + throw new ShapeTreeException(500, "Error parsing ShEx schema - " + ex.getMessage()); + } } // Tell ShExJava we want to use Jena as our graph library let jenaRDF: JenaRDF = new org.apache.commons.rdf.jena.JenaRDF(); @@ -147,9 +148,10 @@ export class ShapeTree { const matchingFocusNode: URL; try { matchingFocusNode = new URL(focusUriString); - } catch (ex: MalformedURLException) { - throw new ShapeTreeException(500, "Error reporting validation success on malformed URL <" + focusUriString + ">: " + ex.getMessage()); - } + } catch (ex) { + if (ex instanceof MalformedURLException) { + throw new ShapeTreeException(500, "Error reporting validation success on malformed URL <" + focusUriString + ">: " + ex.getMessage()); + } return new ValidationResult(valid, this, this, matchingFocusNode); } } diff --git a/asTypescript/packages/core/src/ShapeTreeAssignment.ts b/asTypescript/packages/core/src/ShapeTreeAssignment.ts index 3f029db0..f7b47f23 100644 --- a/asTypescript/packages/core/src/ShapeTreeAssignment.ts +++ b/asTypescript/packages/core/src/ShapeTreeAssignment.ts @@ -37,7 +37,7 @@ export class ShapeTreeAssignment { private readonly url: URL; - public constructor(shapeTree: URL, managedResource: URL, rootAssignment: URL, focusNode: URL, shape: URL, url: URL) throws ShapeTreeException { + public constructor(shapeTree: URL, managedResource: URL, rootAssignment: URL, focusNode: URL, shape: URL, url: URL) /* throws ShapeTreeException */ { try { this.shapeTree = Objects.requireNonNull(shapeTree, "Must provide an assigned shape tree"); this.managedResource = Objects.requireNonNull(managedResource, "Must provide a shape tree context"); @@ -53,9 +53,10 @@ export class ShapeTreeAssignment { } this.focusNode = null; } - } catch (ex: NullPointerException | IllegalStateException) { - throw new ShapeTreeException(500, "Failed to initialize shape tree assignment: " + ex.getMessage()); - } + } catch (ex) { + if (ex instanceof NullPointerException || ex instanceof IllegalStateException) { + throw new ShapeTreeException(500, "Failed to initialize shape tree assignment: " + ex.getMessage()); + } } public static getFromGraph(url: URL, managerGraph: Graph): ShapeTreeAssignment /* throws MalformedURLException, ShapeTreeException */ { diff --git a/asTypescript/packages/core/src/ShapeTreeFactory.ts b/asTypescript/packages/core/src/ShapeTreeFactory.ts index c5e654d3..a74fe58a 100644 --- a/asTypescript/packages/core/src/ShapeTreeFactory.ts +++ b/asTypescript/packages/core/src/ShapeTreeFactory.ts @@ -88,9 +88,10 @@ export class ShapeTreeFactory { private static getContains(resourceModel: Model, shapeTreeNode: Resource, shapeTreeUrl: URL): Array /* throws ShapeTreeException */ { try { return getURLListValue(resourceModel, shapeTreeNode, ShapeTreeVocabulary.CONTAINS); - } catch (ex: MalformedURLException | ShapeTreeException) { - throw new ShapeTreeException(500, "List <" + shapeTreeUrl + "> contains malformed URL: " + ex.getMessage()); - } + } catch (ex) { + if (ex instanceof MalformedURLException || ex instanceof ShapeTreeException) { + throw new ShapeTreeException(500, "List <" + shapeTreeUrl + "> contains malformed URL: " + ex.getMessage()); + } } /** @@ -113,9 +114,10 @@ export class ShapeTreeFactory { let referencedShapeTree: ShapeTreeReference; try { referencedShapeTreeUrl = new URL(referencedShapeTreeUrlString); - } catch (ex: MalformedURLException) { - throw new ShapeTreeException(500, "ShapeTree <" + shapeTreeUrl + "> references malformed URL <" + referencedShapeTreeUrlString + ">: " + ex.getMessage()); - } + } catch (ex) { + if (ex instanceof MalformedURLException) { + throw new ShapeTreeException(500, "ShapeTree <" + shapeTreeUrl + "> references malformed URL <" + referencedShapeTreeUrlString + ">: " + ex.getMessage()); + } let viaShapePath: string = getStringValue(resourceModel, referenceResource, ShapeTreeVocabulary.VIA_SHAPE_PATH); let viaPredicate: URL = getUrlValue(resourceModel, referenceResource, ShapeTreeVocabulary.VIA_PREDICATE, shapeTreeUrl); referencedShapeTree = new ShapeTreeReference(referencedShapeTreeUrl, viaShapePath, viaPredicate); @@ -142,9 +144,10 @@ export class ShapeTreeFactory { if (object.isURIResource()) { try { return new URL(object.asResource().getURI()); - } catch (ex: MalformedURLException) { - throw new IllegalStateException("Malformed ShapeTree <" + shapeTreeUrl + ">: Jena URIResource <" + object + "> didn't parse as URL - " + ex.getMessage()); - } + } catch (ex) { + if (ex instanceof MalformedURLException) { + throw new IllegalStateException("Malformed ShapeTree <" + shapeTreeUrl + ">: Jena URIResource <" + object + "> didn't parse as URL - " + ex.getMessage()); + } } else { throw new ShapeTreeException(500, "Malformed ShapeTree <" + shapeTreeUrl + ">: expected " + object + " to be a URL"); } diff --git a/asTypescript/packages/core/src/ShapeTreeManager.ts b/asTypescript/packages/core/src/ShapeTreeManager.ts index 9841127c..3d9e64f0 100644 --- a/asTypescript/packages/core/src/ShapeTreeManager.ts +++ b/asTypescript/packages/core/src/ShapeTreeManager.ts @@ -103,9 +103,10 @@ export class ShapeTreeManager { const assignmentUrl: URL; try { assignmentUrl = new URL(assignmentString); - } catch (ex: MalformedURLException) { - throw new IllegalStateException("Minted illegal URL <" + assignmentString + "> - " + ex.getMessage()); - } + } catch (ex) { + if (ex instanceof MalformedURLException) { + throw new IllegalStateException("Minted illegal URL <" + assignmentString + "> - " + ex.getMessage()); + } return assignmentUrl; } @@ -163,9 +164,10 @@ export class ShapeTreeManager { let assignment: ShapeTreeAssignment = null; try { assignment = ShapeTreeAssignment.getFromGraph(new URL(assignmentNode.getObject().getURI()), managerGraph); - } catch (e: MalformedURLException) { - throw new ShapeTreeException(500, "Object of { " + s + " " + stAssignment + " " + assignmentNode.getObject() + " } must be a URL."); - } + } catch (ex) { + if (ex instanceof MalformedURLException) { + throw new ShapeTreeException(500, "Object of { " + s + " " + stAssignment + " " + assignmentNode.getObject() + " } must be a URL."); + } manager.assignments.add(assignment); } return manager; diff --git a/asTypescript/packages/core/src/ShapeTreeManagerDelta.ts b/asTypescript/packages/core/src/ShapeTreeManagerDelta.ts index 74537ef3..3cc7643f 100644 --- a/asTypescript/packages/core/src/ShapeTreeManagerDelta.ts +++ b/asTypescript/packages/core/src/ShapeTreeManagerDelta.ts @@ -79,9 +79,10 @@ export class ShapeTreeManagerDelta { try { assignmentUri = assignment.getUrl().toURI(); targetAssignmentUri = targetAssignment.getUrl().toURI(); - } catch (ex: URISyntaxException) { - throw new ShapeTreeException(500, "Unable to convert assignment URLs for comparison: " + ex.getMessage()); - } + } catch (ex) { + if (ex instanceof URISyntaxException) { + throw new ShapeTreeException(500, "Unable to convert assignment URLs for comparison: " + ex.getMessage()); + } if (assignmentUri === targetAssignmentUri) { return targetAssignment; } diff --git a/asTypescript/packages/core/src/ShapeTreeReference.ts b/asTypescript/packages/core/src/ShapeTreeReference.ts index e20c062c..2cb562c4 100644 --- a/asTypescript/packages/core/src/ShapeTreeReference.ts +++ b/asTypescript/packages/core/src/ShapeTreeReference.ts @@ -10,7 +10,7 @@ export class ShapeTreeReference { readonly predicate: URL; - public constructor(referenceUrl: URL, shapePath: string, predicate: URL) throws ShapeTreeException { + public constructor(referenceUrl: URL, shapePath: string, predicate: URL) /* throws ShapeTreeException */ { this.referenceUrl = Objects.requireNonNull(referenceUrl); if (shapePath === null && predicate === null) { throw new ShapeTreeException(500, "Shape tree reference must have either a shape path or a predicate"); diff --git a/asTypescript/packages/core/src/contentloaders/HttpExternalDocumentLoader.ts b/asTypescript/packages/core/src/contentloaders/HttpExternalDocumentLoader.ts index daecfa7b..e0175d42 100644 --- a/asTypescript/packages/core/src/contentloaders/HttpExternalDocumentLoader.ts +++ b/asTypescript/packages/core/src/contentloaders/HttpExternalDocumentLoader.ts @@ -25,13 +25,14 @@ export class HttpExternalDocumentLoader implements ExternalDocumentLoader { } let attributes: ResourceAttributes = new ResourceAttributes(response.headers().map()); return new DocumentResponse(attributes, response.body(), response.statusCode()); - } catch (ex: IOException) { - throw new ShapeTreeException(500, "Error retrieving <" + resourceUrl + ">: " + ex.getMessage()); - } catch (ex: InterruptedException) { - Thread.currentThread().interrupt(); - throw new ShapeTreeException(500, "Error retrieving <" + resourceUrl + ">: " + ex.getMessage()); - } catch (ex: URISyntaxException) { - throw new ShapeTreeException(500, "Malformed URL <" + resourceUrl + ">: " + ex.getMessage()); - } + } catch (ex) { + if (ex instanceof IOException) { + throw new ShapeTreeException(500, "Error retrieving <" + resourceUrl + ">: " + ex.getMessage()); + } else if (ex instanceof InterruptedException) { + Thread.currentThread().interrupt(); + throw new ShapeTreeException(500, "Error retrieving <" + resourceUrl + ">: " + ex.getMessage()); + } else if (ex instanceof URISyntaxException) { + throw new ShapeTreeException(500, "Malformed URL <" + resourceUrl + ">: " + ex.getMessage()); + } } } diff --git a/asTypescript/packages/core/src/helpers/GraphHelper.ts b/asTypescript/packages/core/src/helpers/GraphHelper.ts index 4a35c18f..e7c0c07c 100644 --- a/asTypescript/packages/core/src/helpers/GraphHelper.ts +++ b/asTypescript/packages/core/src/helpers/GraphHelper.ts @@ -77,9 +77,10 @@ export class GraphHelper { let reader: StringReader = new StringReader(rawContent); RDFDataMgr.read(model.getGraph(), reader, baseURI.toString(), GraphHelper.getLangForContentType(contentType)); return model; - } catch (rex: RiotException) { - throw new ShapeTreeException(422, "Error processing input - " + rex.getMessage()); - } + } catch (ex) { + if (ex instanceof RiotException) { + throw new ShapeTreeException(422, "Error processing input - " + rex.getMessage()); + } } /** @@ -160,9 +161,10 @@ export class GraphHelper { public static urlToUri(url: URL): URI { try { return url.toURI(); - } catch (ex: URISyntaxException) { - throw new IllegalStateException("can't convert URL <" + url + "> to IRI: " + ex); - } + } catch (ex) { + if (ex instanceof URISyntaxException) { + throw new IllegalStateException("can't convert URL <" + url + "> to IRI: " + ex); + } } /** @@ -178,16 +180,18 @@ export class GraphHelper { try { let noFragment: URI = new URI(uri.getScheme(), uri.getSchemeSpecificPart(), null); return noFragment.toURL(); - } catch (ex: MalformedURLException | URISyntaxException) { - throw new IllegalStateException("Unable to remove fragment from URL: " + ex.getMessage()); - } + } catch (ex) { + if (ex instanceof MalformedURLException || ex instanceof URISyntaxException) { + throw new IllegalStateException("Unable to remove fragment from URL: " + ex.getMessage()); + } } public static knownUrl(urlString: string): URL { try { return new URL(urlString); - } catch (ex: MalformedURLException) { - throw new IllegalStateException("Expected known URL <" + urlString + "> to parse as valid URL - " + ex.toString()); - } + } catch (ex) { + if (ex instanceof MalformedURLException) { + throw new IllegalStateException("Expected known URL <" + urlString + "> to parse as valid URL - " + ex.toString()); + } } } diff --git a/asTypescript/packages/core/src/helpers/RequestHelper.ts b/asTypescript/packages/core/src/helpers/RequestHelper.ts index 90ab0316..884612f0 100644 --- a/asTypescript/packages/core/src/helpers/RequestHelper.ts +++ b/asTypescript/packages/core/src/helpers/RequestHelper.ts @@ -97,9 +97,10 @@ export class RequestHelper { try { const focusNodeUrl: URL = new URL(baseUrl, focusNodeUrlString); focusNodeUrls.add(focusNodeUrl); - } catch (e: MalformedURLException) { - throw new ShapeTreeException(500, "Malformed focus node when resolving <" + focusNodeUrlString + "> against <" + baseUrl + ">"); - } + } catch (ex) { + if (ex instanceof MalformedURLException) { + throw new ShapeTreeException(500, "Malformed focus node when resolving <" + focusNodeUrlString + "> against <" + baseUrl + ">"); + } } } return focusNodeUrls; @@ -119,9 +120,10 @@ export class RequestHelper { try { const targetShapeTreeUrl: URL = new URL(targetShapeTreeUrlString); targetShapeTreeUrls.add(targetShapeTreeUrl); - } catch (e: MalformedURLException) { - throw new ShapeTreeException(500, "Malformed focus node when resolving <" + targetShapeTreeUrlString + "> against <" + baseUrl + ">"); - } + } catch (ex) { + if (ex instanceof MalformedURLException) { + throw new ShapeTreeException(500, "Malformed focus node when resolving <" + targetShapeTreeUrlString + "> against <" + baseUrl + ">"); + } } } return targetShapeTreeUrls; @@ -153,9 +155,10 @@ export class RequestHelper { } try { return new URL(urlString); - } catch (ex: MalformedURLException) { - throw new ShapeTreeException(500, "normalized to malformed URL <" + urlString + "> - " + ex.getMessage()); - } + } catch (ex) { + if (ex instanceof MalformedURLException) { + throw new ShapeTreeException(500, "normalized to malformed URL <" + urlString + "> - " + ex.getMessage()); + } } /** diff --git a/asTypescript/packages/javahttp/src/JavaHttpClient.ts b/asTypescript/packages/javahttp/src/JavaHttpClient.ts index 325d9c91..8bffef1e 100644 --- a/asTypescript/packages/javahttp/src/JavaHttpClient.ts +++ b/asTypescript/packages/javahttp/src/JavaHttpClient.ts @@ -39,9 +39,10 @@ export class JavaHttpClient implements HttpClient { let body: string = null; try { body = Objects.requireNonNull(response.body()).toString(); - } catch (ex: NullPointerException) { - log.error("Exception retrieving body string"); - } + } catch (ex) { + if (ex instanceof NullPointerException) { + log.error("Exception retrieving body string"); + } return new DocumentResponse(new ResourceAttributes(response.headers().map()), body, response.statusCode()); } @@ -52,7 +53,7 @@ export class JavaHttpClient implements HttpClient { * @throws NoSuchAlgorithmException potentially thrown while disabling SSL validation * @throws KeyManagementException potentially thrown while disabling SSL validation */ - protected constructor(useSslValidation: boolean, useShapeTreeValidation: boolean) throws NoSuchAlgorithmException, KeyManagementException { + protected constructor(useSslValidation: boolean, useShapeTreeValidation: boolean) /* throws NoSuchAlgorithmException, KeyManagementException */ { let clientBuilder: java.net.http.HttpClient.Builder = java.net.http.HttpClient.newBuilder(); this.validatingWrapper = null; if (Boolean.TRUE === useShapeTreeValidation) { @@ -74,14 +75,16 @@ export class JavaHttpClient implements HttpClient { let sc: SSLContext = null; try { sc = SSLContext.getInstance("TLSv1.2"); - } catch (e: NoSuchAlgorithmException) { - e.printStackTrace(); - } + } catch (ex) { + if (ex instanceof NoSuchAlgorithmException) { + e.printStackTrace(); + } try { sc.init(null, trustAllCerts, new java.security.SecureRandom()); - } catch (e: KeyManagementException) { - e.printStackTrace(); - } + } catch (ex) { + if (ex instanceof KeyManagementException) { + e.printStackTrace(); + } HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); // Create all-trusting host name verifier let validHosts: HostnameVerifier = new HostnameVerifier() { @@ -134,11 +137,12 @@ export class JavaHttpClient implements HttpClient { } else { return this.validatingWrapper.validatingWrap(nativeRequest, this.httpClient, request.body, request.contentType); } - } catch (ex: IOException | InterruptedException) { - throw new ShapeTreeException(500, ex.getMessage()); - } catch (ex: URISyntaxException) { - throw new ShapeTreeException(500, "Malformed URL <" + request.resourceURL + ">: " + ex.getMessage()); - } + } catch (ex) { + if (ex instanceof IOException || ex instanceof InterruptedException) { + throw new ShapeTreeException(500, ex.getMessage()); + } else if (ex instanceof URISyntaxException) { + throw new ShapeTreeException(500, "Malformed URL <" + request.resourceURL + ">: " + ex.getMessage()); + } } protected static check(resp: java.net.http.HttpResponse): java.net.http.HttpResponse { diff --git a/asTypescript/packages/javahttp/src/JavaHttpClientFactory.ts b/asTypescript/packages/javahttp/src/JavaHttpClientFactory.ts index b462bec6..755b4977 100644 --- a/asTypescript/packages/javahttp/src/JavaHttpClientFactory.ts +++ b/asTypescript/packages/javahttp/src/JavaHttpClientFactory.ts @@ -36,9 +36,10 @@ export class JavaHttpClientFactory implements HttpClientFactory, ExternalDocumen public get(useShapeTreeValidation: boolean): JavaHttpClient /* throws ShapeTreeException */ { try { return new JavaHttpClient(this.useSslValidation, useShapeTreeValidation); - } catch (ex: Exception) { - throw new ShapeTreeException(500, ex.getMessage()); - } + } catch (ex) { + if (ex instanceof Exception) { + throw new ShapeTreeException(500, ex.getMessage()); + } } /** diff --git a/asTypescript/packages/javahttp/src/JavaHttpValidatingShapeTreeInterceptor.ts b/asTypescript/packages/javahttp/src/JavaHttpValidatingShapeTreeInterceptor.ts index e2b52a5d..74c361f8 100644 --- a/asTypescript/packages/javahttp/src/JavaHttpValidatingShapeTreeInterceptor.ts +++ b/asTypescript/packages/javahttp/src/JavaHttpValidatingShapeTreeInterceptor.ts @@ -47,13 +47,14 @@ export class JavaHttpValidatingShapeTreeInterceptor { } else { return createResponse(clientRequest, shapeTreeResponse.get()); } - } catch (ex: ShapeTreeException) { - log.error("Error processing shape tree request: ", ex); - return createErrorResponse(ex, clientRequest); - } catch (ex: Exception) { - log.error("Error processing shape tree request: ", ex); - return createErrorResponse(new ShapeTreeException(500, ex.getMessage()), clientRequest); - } + } catch (ex) { + if (ex instanceof ShapeTreeException) { + log.error("Error processing shape tree request: ", ex); + return createErrorResponse(ex, clientRequest); + } else if (ex instanceof Exception) { + log.error("Error processing shape tree request: ", ex); + return createErrorResponse(new ShapeTreeException(500, ex.getMessage()), clientRequest); + } } else { log.warn("No handler for method [{}] - passing through request", shapeTreeRequest.getMethod()); return JavaHttpClient.check(httpClient.send(clientRequest, java.net.http.HttpResponse.BodyHandlers.ofString())); @@ -116,9 +117,10 @@ export class JavaHttpValidatingShapeTreeInterceptor { override public getUrl(): URL { try { return this.request.uri().toURL(); - } catch (ex: MalformedURLException) { - throw new IllegalStateException("request has a malformed URL <" + request.uri() + ">: " + ex.getMessage()); - } + } catch (ex) { + if (ex instanceof MalformedURLException) { + throw new IllegalStateException("request has a malformed URL <" + request.uri() + ">: " + ex.getMessage()); + } } override public getHeaders(): ResourceAttributes {