-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
ProblemDetails
for invalid policy conditions
The frontend can properly interpret `ProblemDetails` and present a more helpful error message to users than the current generic "request failed" one. Signed-off-by: nscuro <[email protected]>
- Loading branch information
Showing
7 changed files
with
122 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...in/java/org/dependencytrack/resources/v1/problems/InvalidCelExpressionProblemDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* This file is part of Dependency-Track. | ||
* | ||
* 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright (c) OWASP Foundation. All Rights Reserved. | ||
*/ | ||
package org.dependencytrack.resources.v1.problems; | ||
|
||
import io.swagger.annotations.ApiModelProperty; | ||
import io.swagger.annotations.ApiParam; | ||
import org.projectnessie.cel.Issues; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @since 5.5.0 | ||
*/ | ||
public class InvalidCelExpressionProblemDetails extends ProblemDetails { | ||
|
||
public record CelExpressionError( | ||
@ApiParam(value = "The line in which the error was identified") Integer line, | ||
@ApiParam(value = "The column in which the error was identified") Integer column, | ||
@ApiParam(value = "The message describing the error") String message | ||
) { | ||
} | ||
|
||
@ApiModelProperty(value = "Errors identified during expression compilation") | ||
private final List<CelExpressionError> errors; | ||
|
||
public InvalidCelExpressionProblemDetails(final Issues issues) { | ||
this.errors = issues.getErrors().stream() | ||
.map(error -> new CelExpressionError( | ||
error.getLocation().line(), | ||
error.getLocation().column(), | ||
error.getMessage() | ||
)) | ||
.toList(); | ||
} | ||
|
||
public List<CelExpressionError> getErrors() { | ||
return errors; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
src/main/java/org/dependencytrack/resources/v1/vo/CelExpressionError.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters