private List<QualityProfile> handleErrors(@Nullable String profileName, StringBuilder url, Supplier<String> errorMsg) { try { return loadAndOverrideIfNeeded(profileName, url); } catch (HttpException e) { if (e.code() == 404) { throw MessageException.of(errorMsg.get() + ": " + ScannerWsClient.createErrorMessage(e)); } throw new IllegalStateException(errorMsg.get() + ": " + ScannerWsClient.createErrorMessage(e)); } catch (MessageException e) { throw e; } catch (Exception e) { throw new IllegalStateException(errorMsg.get(), e); } }
@Test public void create_error_msg_from_json() { String content = "{\"errors\":[{\"msg\":\"missing scan permission\"}, {\"msg\":\"missing another permission\"}]}"; assertThat(ScannerWsClient.createErrorMessage(new HttpException("url", 400, content))).isEqualTo("missing scan permission, missing another permission"); }
@Test public void create_error_msg_from_html() { String content = "<!DOCTYPE html><html>something</html>"; assertThat(ScannerWsClient.createErrorMessage(new HttpException("url", 400, content))).isEqualTo("HTTP code 400"); }
@Test public void create_error_msg_from_long_content() { String content = StringUtils.repeat("mystring", 1000); assertThat(ScannerWsClient.createErrorMessage(new HttpException("url", 400, content))).hasSize(15 + 128); }
response = wsClient.call(post).failIfNotSuccessful(); } catch (HttpException e) { throw MessageException.of(String.format("Failed to upload report - %s", ScannerWsClient.createErrorMessage(e)));
private List<QualityProfile> handleErrors(@Nullable String profileName, StringBuilder url, Supplier<String> errorMsg) { try { return loadAndOverrideIfNeeded(profileName, url); } catch (HttpException e) { if (e.code() == 404) { throw MessageException.of(errorMsg.get() + ": " + ScannerWsClient.createErrorMessage(e)); } throw new IllegalStateException(errorMsg.get() + ": " + ScannerWsClient.createErrorMessage(e)); } catch (MessageException e) { throw e; } catch (Exception e) { throw new IllegalStateException(errorMsg.get(), e); } }
response = wsClient.call(post).failIfNotSuccessful(); } catch (HttpException e) { throw MessageException.of(String.format("Failed to upload report - %s", ScannerWsClient.createErrorMessage(e)));