Throw the API exception with authorization URL on SCMunauthorised error

pull/621/head
ivinokur 2023-12-01 13:04:13 +02:00
parent 7acf4cc2d9
commit dbf057a963
2 changed files with 5 additions and 2 deletions

View File

@ -30,6 +30,7 @@ import javax.inject.Named;
import javax.inject.Singleton;
import org.eclipse.che.api.core.ApiException;
import org.eclipse.che.api.core.BadRequestException;
import org.eclipse.che.api.factory.server.scm.exception.ScmUnauthorizedException;
import org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl.DevfileLocation;
import org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto;
import org.eclipse.che.api.factory.shared.dto.FactoryDto;
@ -131,7 +132,9 @@ public class URLFactoryBuilder {
continue;
} catch (DevfileException e) {
LOG.debug("Unexpected devfile exception: {}", e.getMessage());
throw new ApiException(e.getMessage());
throw e.getCause() instanceof ScmUnauthorizedException
? toApiException(e, location)
: new ApiException(e.getMessage());
}
if (isNullOrEmpty(devfileYamlContent)) {
return Optional.empty();

View File

@ -451,7 +451,7 @@ public class URLFactoryBuilderTest {
} catch (ApiException e) {
assertTrue(e.getClass().isAssignableFrom(expectedClass));
assertEquals(e.getMessage(), expectedMessage);
if (e.getServiceError() instanceof ExtendedError)
if ("SCM Authentication required".equals(e.getMessage()))
assertEquals(((ExtendedError) e.getServiceError()).getAttributes(), expectedAttributes);
}
}