Align the unreachable devfile exception message

pull/615/head
ivinokur 2023-11-16 15:03:04 +02:00
parent 6ca7127939
commit a2b51bb3e4
4 changed files with 26 additions and 5 deletions

View File

@ -13,6 +13,7 @@ package org.eclipse.che.api.factory.server.scm;
import static com.google.common.base.Strings.isNullOrEmpty;
import static org.eclipse.che.api.factory.server.scm.PersonalAccessTokenFetcher.OAUTH_2_PREFIX;
import static org.eclipse.che.api.factory.server.scm.exception.ExceptionMessages.getDevfileConnectionErrorMessage;
import java.io.FileNotFoundException;
import java.io.IOException;
@ -123,7 +124,7 @@ public class AuthorizingFileContentProvider<T extends RemoteFactoryUrl>
}
}
throw new DevfileException(
"Could not reach devfile at " + "`" + exception.getMessage() + "`", exception);
getDevfileConnectionErrorMessage(exception.getMessage()), exception);
}
}

View File

@ -0,0 +1,18 @@
/*
* Copyright (c) 2012-2023 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.factory.server.scm.exception;
public class ExceptionMessages {
public static String getDevfileConnectionErrorMessage(String location) {
return String.format("Could not reach devfile at %s", location);
}
}

View File

@ -13,6 +13,7 @@ package org.eclipse.che.api.factory.server.urlfactory;
import static com.google.common.base.Strings.isNullOrEmpty;
import static org.eclipse.che.api.factory.server.ApiExceptionMapper.toApiException;
import static org.eclipse.che.api.factory.server.scm.exception.ExceptionMessages.getDevfileConnectionErrorMessage;
import static org.eclipse.che.api.factory.shared.Constants.CURRENT_VERSION;
import static org.eclipse.che.api.workspace.server.devfile.Constants.CURRENT_API_VERSION;
import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_EDITOR_ATTRIBUTE;
@ -130,7 +131,7 @@ public class URLFactoryBuilder {
continue;
} catch (DevfileException e) {
LOG.debug("Unexpected devfile exception: {}", e.getMessage());
throw toApiException(e, location);
throw new ApiException(e.getMessage());
}
if (isNullOrEmpty(devfileYamlContent)) {
return Optional.empty();
@ -142,7 +143,7 @@ public class URLFactoryBuilder {
try {
devfileVersionDetector.devfileVersion(parsedDevfile);
} catch (DevfileException e) {
throw new ApiException("Failed to fetch devfile");
throw new ApiException(getDevfileConnectionErrorMessage(devfileLocation));
}
return Optional.of(
createFactory(parsedDevfile, overrideProperties, fileContentProvider, location));

View File

@ -441,7 +441,8 @@ public class URLFactoryBuilderTest {
}
}));
when(fileContentProvider.fetchContent(anyString())).thenThrow(new DevfileException("", cause));
when(fileContentProvider.fetchContent(anyString()))
.thenThrow(new DevfileException(expectedMessage, cause));
// when
try {
@ -457,7 +458,7 @@ public class URLFactoryBuilderTest {
@Test(
expectedExceptions = ApiException.class,
expectedExceptionsMessageRegExp = "Failed to fetch devfile")
expectedExceptionsMessageRegExp = "Could not reach devfile at location")
public void shouldThrowErrorOnUnsupportedDevfileContent()
throws ApiException, DevfileException, IOException {
JsonNode jsonNode = mock(JsonNode.class);