Skip to content

Commit

Permalink
populating the exception with more detail
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Kerwin committed Mar 26, 2021
1 parent 41f6e60 commit db176a0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ plugins { id 'groovy' }
project.ext.moduleName = 'com.synopsys.integration.integration-rest'
project.ext.junitShowStandardStreams = 'true'

version = '7.1.3-SNAPSHOT'
version = '8.0.0-SNAPSHOT'
description = 'A library wrapping http communication for integrations.'

apply plugin: 'com.synopsys.integration.library'

dependencies {
api 'com.synopsys.integration:integration-common:24.2.0'
api 'com.synopsys.integration:integration-common:24.2.1'

api 'org.apache.httpcomponents:httpclient:4.5.13'
api 'org.apache.httpcomponents:httpmime:4.5.13'

testImplementation 'org.codehaus.groovy:groovy-all:2.4.12'
testImplementation 'com.squareup.okhttp3:mockwebserver:3.9.0'
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/synopsys/integration/rest/HttpMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*/
package com.synopsys.integration.rest;

import org.apache.commons.lang3.StringUtils;

public enum HttpMethod {
GET,
PUT,
Expand All @@ -32,4 +34,8 @@ public enum HttpMethod {
OPTIONS,
TRACE;

public static HttpMethod fromMethod(String method) {
return HttpMethod.valueOf(StringUtils.upperCase(method));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import org.apache.http.impl.client.CloseableHttpClient;

import com.synopsys.integration.exception.IntegrationException;
import com.synopsys.integration.rest.HttpMethod;
import com.synopsys.integration.rest.HttpUrl;
import com.synopsys.integration.rest.RestConstants;
import com.synopsys.integration.rest.exception.IntegrationRestException;

Expand Down Expand Up @@ -210,8 +212,17 @@ public void throwExceptionForError() throws IntegrationRestException {
}

String messageFormat = "There was a problem trying to %s %s, response was %s %s%s.";
String message = String.format(messageFormat, request.getMethod(), request.getURI().toString(), statusCode, statusCodeDescription, reasonPhraseDescription);
throw new IntegrationRestException(statusCode, statusMessage, httpResponseContent, message);
HttpMethod httpMethod = HttpMethod.fromMethod(request.getMethod());
//ejk - seems unlikey that we'd get here without a valid url...
HttpUrl httpUrl = null;
try {
httpUrl = new HttpUrl(request.getURI());
} catch (IntegrationException ignored) {
//ignored
}

String message = String.format(messageFormat, httpMethod, httpUrl.string(), statusCode, statusCodeDescription, reasonPhraseDescription);
throw new IntegrationRestException(httpMethod, httpUrl, statusCode, statusMessage, httpResponseContent, message);
}
}

Expand Down

0 comments on commit db176a0

Please sign in to comment.