|
| 1 | +/* |
| 2 | + * The MIT License |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | + * of this software and associated documentation files (the "Software"), to deal |
| 6 | + * in the Software without restriction, including without limitation the rights |
| 7 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | + * copies of the Software, and to permit persons to whom the Software is |
| 9 | + * furnished to do so, subject to the following conditions: |
| 10 | + * |
| 11 | + * The above copyright notice and this permission notice shall be included in |
| 12 | + * all copies or substantial portions of the Software. |
| 13 | + * |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | + * THE SOFTWARE. |
| 21 | + */ |
| 22 | +package com.influxdb.v3.client; |
| 23 | + |
| 24 | +import java.net.http.HttpHeaders; |
| 25 | +import java.util.List; |
| 26 | +import javax.annotation.Nonnull; |
| 27 | +import javax.annotation.Nullable; |
| 28 | + |
| 29 | +/** |
| 30 | + * HTTP exception for partial write errors returned by InfluxDB 3 write endpoint. |
| 31 | + * Contains parsed line-level write errors so callers can decide how to handle failed lines. |
| 32 | + */ |
| 33 | +public class InfluxDBPartialWriteException extends InfluxDBApiHttpException { |
| 34 | + |
| 35 | + private final List<LineError> lineErrors; |
| 36 | + |
| 37 | + /** |
| 38 | + * Construct a new InfluxDBPartialWriteException. |
| 39 | + * |
| 40 | + * @param message detail message |
| 41 | + * @param headers response headers |
| 42 | + * @param statusCode response status code |
| 43 | + * @param lineErrors line-level errors parsed from response body |
| 44 | + */ |
| 45 | + public InfluxDBPartialWriteException( |
| 46 | + @Nullable final String message, |
| 47 | + @Nullable final HttpHeaders headers, |
| 48 | + final int statusCode, |
| 49 | + @Nonnull final List<LineError> lineErrors) { |
| 50 | + super(message, headers, statusCode); |
| 51 | + this.lineErrors = List.copyOf(lineErrors); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Line-level write errors. |
| 56 | + * |
| 57 | + * @return immutable list of line errors |
| 58 | + */ |
| 59 | + @Nonnull |
| 60 | + public List<LineError> lineErrors() { |
| 61 | + return lineErrors; |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Represents one failed line from a partial write response. |
| 66 | + */ |
| 67 | + public static final class LineError { |
| 68 | + |
| 69 | + private final Integer lineNumber; |
| 70 | + private final String errorMessage; |
| 71 | + private final String originalLine; |
| 72 | + |
| 73 | + /** |
| 74 | + * @param lineNumber line number in the write payload; may be null if not provided by server |
| 75 | + * @param errorMessage line-level error message |
| 76 | + * @param originalLine original line protocol row; may be null if not provided by server |
| 77 | + */ |
| 78 | + public LineError(@Nullable final Integer lineNumber, |
| 79 | + @Nonnull final String errorMessage, |
| 80 | + @Nullable final String originalLine) { |
| 81 | + this.lineNumber = lineNumber; |
| 82 | + this.errorMessage = errorMessage; |
| 83 | + this.originalLine = originalLine; |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * @return line number or null if server didn't provide it |
| 88 | + */ |
| 89 | + @Nullable |
| 90 | + public Integer lineNumber() { |
| 91 | + return lineNumber; |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * @return line-level error message |
| 96 | + */ |
| 97 | + @Nonnull |
| 98 | + public String errorMessage() { |
| 99 | + return errorMessage; |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * @return original line protocol row or null if server didn't provide it |
| 104 | + */ |
| 105 | + @Nullable |
| 106 | + public String originalLine() { |
| 107 | + return originalLine; |
| 108 | + } |
| 109 | + } |
| 110 | +} |
0 commit comments