diff --git a/src/main/groovy/org/ods/doc/gen/core/api/HealthController.groovy b/src/main/groovy/org/ods/doc/gen/core/api/HealthController.groovy index 67078a60..cf6fbd51 100644 --- a/src/main/groovy/org/ods/doc/gen/core/api/HealthController.groovy +++ b/src/main/groovy/org/ods/doc/gen/core/api/HealthController.groovy @@ -34,7 +34,7 @@ class HealthController { return result } - private generatePdfData() { + private void generatePdfData() { Path tmpDir = Files.createTempDirectory("generatePdfDataFolderTest") def documentHtmlFile = Files.createTempFile("document", ".html") << "document" @@ -44,8 +44,6 @@ class HealthController { if (!new String(data).startsWith("%PDF-1.4\n")) { throw new RuntimeException("Conversion form HTML to PDF failed, corrupt data.") } - } catch (e) { - throw new RuntimeException("Conversion form HTML to PDF failed, corrupt data.", e) } finally { Files.delete(documentHtmlFile) FileUtils.deleteDirectory(tmpDir.toFile()) diff --git a/src/main/groovy/org/ods/doc/gen/external/modules/git/BitbucketService.groovy b/src/main/groovy/org/ods/doc/gen/external/modules/git/BitbucketService.groovy index 55bd1e3b..b4bdc2ea 100644 --- a/src/main/groovy/org/ods/doc/gen/external/modules/git/BitbucketService.groovy +++ b/src/main/groovy/org/ods/doc/gen/external/modules/git/BitbucketService.groovy @@ -67,14 +67,17 @@ class BitbucketService { } protected void downloadRepoWithFallBack(String project, String repo, String branch, Path zipArchive) { - try { - bitBucketClientConfig - .getClient() - .getRepoZipArchive(project, repo, branch) - .withCloseable { Response response -> + boolean found = false; + bitBucketClientConfig + .getClient() + .getRepoZipArchive(project, repo, branch) + .withCloseable { Response response -> + if (response.status() != 404) { streamResult(response, zipArchive) + found = true; } - } catch (Exception callException) { + } + if (!found) { log.warn("Branch [${branch}] doesn't exist, using branch: [${MAIN_BRANCH}]") bitBucketClientConfig .getClient() diff --git a/src/main/groovy/org/ods/doc/gen/external/modules/jira/JiraService.groovy b/src/main/groovy/org/ods/doc/gen/external/modules/jira/JiraService.groovy index 00273f79..af182b27 100644 --- a/src/main/groovy/org/ods/doc/gen/external/modules/jira/JiraService.groovy +++ b/src/main/groovy/org/ods/doc/gen/external/modules/jira/JiraService.groovy @@ -43,10 +43,11 @@ class JiraService { } try { - this.baseURL = new URIBuilder(baseURL).build() - this.targetURL = new URIBuilder(baseURL).build() - } catch (e) { - throw new IllegalArgumentException("Error: unable to connect to Jira. '${baseURL}' is not a valid URI.").initCause(e) + URI jiraURI = new URIBuilder(baseURL).build() + this.baseURL = jiraURI + this.targetURL = jiraURI + } catch (URISyntaxException e) { + throw new IllegalArgumentException("FATAL: Jira URL is invalid: jira.url='${baseURL}'", e) } this.username = username diff --git a/src/main/groovy/org/ods/doc/gen/external/modules/nexus/NexusService.groovy b/src/main/groovy/org/ods/doc/gen/external/modules/nexus/NexusService.groovy index eff08acc..186a016b 100644 --- a/src/main/groovy/org/ods/doc/gen/external/modules/nexus/NexusService.groovy +++ b/src/main/groovy/org/ods/doc/gen/external/modules/nexus/NexusService.groovy @@ -34,10 +34,8 @@ class NexusService { checkParams(baseURL, username, password) try { this.baseURL = new URIBuilder(baseURL).build() - } catch (e) { - throw new IllegalArgumentException( - "Error: unable to connect to Nexus. '${baseURL}' is not a valid URI." - ).initCause(e) + } catch (URISyntaxException e) { + throw new IllegalArgumentException("FATAL: Nexus URL is invalid: nexus.url=${baseURL}", e) } this.username = username diff --git a/src/main/groovy/org/ods/doc/gen/external/modules/xunit/JUnitReportsService.groovy b/src/main/groovy/org/ods/doc/gen/external/modules/xunit/JUnitReportsService.groovy index 22d5b332..d8482cc4 100644 --- a/src/main/groovy/org/ods/doc/gen/external/modules/xunit/JUnitReportsService.groovy +++ b/src/main/groovy/org/ods/doc/gen/external/modules/xunit/JUnitReportsService.groovy @@ -59,7 +59,7 @@ class JUnitReportsService { tests.each { String targetFolder = it.value.targetFolder as String - Map testResult = getTestResults(it.key.capitalize(), targetFolder, component) + Map testResult = getTestResults(targetFolder) it.value.testReportFiles = testResult.testReportFiles it.value.testResults = testResult.testResults } @@ -104,7 +104,7 @@ class JUnitReportsService { return testData } - private Map getTestResults(String typeIn, String targetFolder, String component) { + private Map getTestResults(String targetFolder) { if (targetFolder == null) { // When targetFolder is null, we need to initialize testsuites !! return [ diff --git a/src/main/groovy/org/ods/doc/gen/leva/doc/api/LevaDocController.groovy b/src/main/groovy/org/ods/doc/gen/leva/doc/api/LevaDocController.groovy index c2a380db..4b06b9ea 100644 --- a/src/main/groovy/org/ods/doc/gen/leva/doc/api/LevaDocController.groovy +++ b/src/main/groovy/org/ods/doc/gen/leva/doc/api/LevaDocController.groovy @@ -70,14 +70,12 @@ class LevaDocController { try { prepareServiceDataParam(projectId, buildNumber, levaDocType, data) return levaDocType.buildDocument.apply(leVADocumentService, data) - } catch (Throwable e) { - String msg = "Error building document: ${levaDocType} with data:${data}" - log.error(msg, e) - String msgWithDetails = msg; - if (! StringUtils.isEmpty(e.getMessage())) { - msgWithDetails = msg + ". " + e.getMessage(); + } catch (e) { + if (log.isDebugEnabled()) { + String msg = "Error building document: ${levaDocType} with data:${data}" + log.debug(msg, e) } - throw new RuntimeException(msgWithDetails, e) + throw e } } diff --git a/src/main/groovy/org/ods/doc/gen/leva/doc/services/DocGenService.groovy b/src/main/groovy/org/ods/doc/gen/leva/doc/services/DocGenService.groovy index 6d74de43..b2bbc46b 100644 --- a/src/main/groovy/org/ods/doc/gen/leva/doc/services/DocGenService.groovy +++ b/src/main/groovy/org/ods/doc/gen/leva/doc/services/DocGenService.groovy @@ -33,12 +33,8 @@ class DocGenService { private Path convertToPdf(Map body) { Path tmpDir Path documentPdf - try { - tmpDir = Files.createTempDirectory("${body.metadata.type}-v${body.metadata.version}") - documentPdf = pdfGenerationService.generatePdfFile(body.metadata as Map, body.data as Map, tmpDir) - } catch (Throwable e) { - throw new RuntimeException("Conversion form HTML to PDF failed, corrupt data.", e) - } + tmpDir = Files.createTempDirectory("${body.metadata.type}-v${body.metadata.version}") + documentPdf = pdfGenerationService.generatePdfFile(body.metadata as Map, body.data as Map, tmpDir) return documentPdf } diff --git a/src/main/groovy/org/ods/doc/gen/pdf/builder/api/DocGenController.groovy b/src/main/groovy/org/ods/doc/gen/pdf/builder/api/DocGenController.groovy index a62d5762..e0981a8a 100644 --- a/src/main/groovy/org/ods/doc/gen/pdf/builder/api/DocGenController.groovy +++ b/src/main/groovy/org/ods/doc/gen/pdf/builder/api/DocGenController.groovy @@ -61,18 +61,14 @@ class DocGenController { } private Path convertToPdf(Map body, Path tmpDir) { - try { - Path documentPdf = pdfGeneration.generatePdfFile(body.metadata as Map, body.data as Map, tmpDir) - Path tempFile = Files.createTempFile(tmpDir, 'temp', '.b64') - tempFile.toFile().withOutputStream { os -> - Base64.getEncoder().wrap(os).withStream { encOs -> - Files.copy(documentPdf, encOs) - } + Path documentPdf = pdfGeneration.generatePdfFile(body.metadata as Map, body.data as Map, tmpDir) + Path tempFile = Files.createTempFile(tmpDir, 'temp', '.b64') + tempFile.toFile().withOutputStream { os -> + Base64.getEncoder().wrap(os).withStream { encOs -> + Files.copy(documentPdf, encOs) } - return tempFile - } catch (Throwable e) { - throw new RuntimeException("Conversion form HTML to PDF failed, corrupt data.", e) } + return tempFile } private static void logData(Map body) { diff --git a/src/main/groovy/org/ods/doc/gen/pdf/builder/api/RestResponseEntityExceptionHandler.groovy b/src/main/groovy/org/ods/doc/gen/pdf/builder/api/RestResponseEntityExceptionHandler.groovy index e3d7ebf3..2e647ba4 100644 --- a/src/main/groovy/org/ods/doc/gen/pdf/builder/api/RestResponseEntityExceptionHandler.groovy +++ b/src/main/groovy/org/ods/doc/gen/pdf/builder/api/RestResponseEntityExceptionHandler.groovy @@ -13,16 +13,16 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExcep @ControllerAdvice class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler { - @ExceptionHandler(value = [ IllegalArgumentException.class ]) - protected ResponseEntity handleArgumentError(RuntimeException ex, WebRequest request) { - log.error("ExceptionHandler, handleArgumentError:${ex.message}", ex) - return handleExceptionInternal(ex, ex.message, new HttpHeaders(), HttpStatus.PRECONDITION_FAILED, request) + @ExceptionHandler(value = IllegalArgumentException.class) + protected ResponseEntity handleArgumentError(IllegalArgumentException ex, WebRequest request) { + log.error("Bad request: ", ex) + return handleExceptionInternal(ex, ex.message, new HttpHeaders(), HttpStatus.BAD_REQUEST, request) } - @ExceptionHandler(value = [ RuntimeException.class ]) + @ExceptionHandler(value = RuntimeException.class) protected ResponseEntity runtimeError(RuntimeException ex, WebRequest request) { - log.error("ExceptionHandler, runtimeError:${ex.message}", ex) - return handleExceptionInternal(ex, ex.message, new HttpHeaders(), HttpStatus.CONFLICT, request) + log.error("Internal server error: ", ex) + return handleExceptionInternal(ex, ex.message, new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR, request) } } \ No newline at end of file