Rationalize exception management

This commit is contained in:
Stephane Nicoll 2019-02-08 11:00:04 +01:00
parent 478c0c41c6
commit cd3b274112
6 changed files with 6 additions and 49 deletions

View File

@ -1,35 +0,0 @@
/*
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring.initializr;
/**
* Base Initializr exception.
*
* @author Stephane Nicoll
*/
@SuppressWarnings("serial")
public class InitializrException extends RuntimeException {
public InitializrException(String message, Throwable cause) {
super(message, cause);
}
public InitializrException(String message) {
super(message);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,7 +26,6 @@ import javax.servlet.http.HttpServletResponse;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.metadata.TypeCapability;
import io.spring.initializr.web.InvalidProjectRequestException;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.http.HttpStatus;

View File

@ -14,9 +14,9 @@
* limitations under the License.
*/
package io.spring.initializr.web;
package io.spring.initializr.web.project;
import io.spring.initializr.InitializrException;
import io.spring.initializr.generator.project.ProjectGenerationException;
/**
* Thrown when a {@link ProjectRequest} is invalid.
@ -24,11 +24,7 @@ import io.spring.initializr.InitializrException;
* @author Stephane Nicoll
*/
@SuppressWarnings("serial")
public class InvalidProjectRequestException extends InitializrException {
public InvalidProjectRequestException(String message, Throwable cause) {
super(message, cause);
}
public class InvalidProjectRequestException extends ProjectGenerationException {
public InvalidProjectRequestException(String message) {
super(message);

View File

@ -25,7 +25,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import io.spring.initializr.InitializrException;
import io.spring.initializr.generator.buildsystem.Build;
import io.spring.initializr.generator.buildsystem.BuildItemResolver;
import io.spring.initializr.generator.project.DefaultProjectAssetGenerator;
@ -92,7 +91,7 @@ public class ProjectGenerationInvoker {
addTempFile(name, file);
return file;
}
catch (ProjectGenerationException | InitializrException ex) {
catch (ProjectGenerationException ex) {
publishProjectFailedEvent(request, metadata, ex);
throw ex;
}
@ -124,7 +123,7 @@ public class ProjectGenerationInvoker {
projectGenerationContext, metadata));
return projectGenerator.generate(projectDescription, generateBuild(request));
}
catch (ProjectGenerationException | InitializrException ex) {
catch (ProjectGenerationException ex) {
publishProjectFailedEvent(request, metadata, ex);
throw ex;
}

View File

@ -31,7 +31,6 @@ import io.spring.initializr.metadata.DefaultMetadataElement;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.Type;
import io.spring.initializr.web.InvalidProjectRequestException;
import org.springframework.util.StringUtils;

View File

@ -22,7 +22,6 @@ import io.spring.initializr.generator.project.ProjectDescription;
import io.spring.initializr.generator.spring.test.InitializrMetadataTestBuilder;
import io.spring.initializr.generator.version.Version;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.web.InvalidProjectRequestException;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;