forked from oras-project/oras-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrasException.java
More file actions
80 lines (70 loc) · 1.74 KB
/
OrasException.java
File metadata and controls
80 lines (70 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package land.oras;
import land.oras.utils.JsonUtils;
import land.oras.utils.OrasHttpClient;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Exception for ORAS
*/
@NullMarked
public class OrasException extends RuntimeException {
/**
* Logger
*/
private static final Logger LOG = LoggerFactory.getLogger(OrasException.class);
/**
* Possible error response
*/
private @Nullable Error error;
/**
* Status code
*/
private @Nullable Integer statusCode;
/**
* Constructor
* @param message The message
*/
public OrasException(String message) {
super(message);
}
/**
* New exception with a message and a response
* @param response The response
*/
public OrasException(OrasHttpClient.ResponseWrapper<String> response) {
this("Response code: " + response.statusCode());
try {
this.statusCode = response.statusCode();
error = JsonUtils.fromJson(response.response(), Error.class);
} catch (Exception e) {
LOG.debug("Failed to parse error response", e);
}
}
/**
* Constructor
* @param message The message
* @param cause The cause
*/
public OrasException(String message, Throwable cause) {
super(message, cause);
}
/**
* Get the error
* @return The error
*/
public @Nullable Error getError() {
return error;
}
/**
* Get the status code
* @return The status code
*/
public Integer getStatusCode() {
if (statusCode == null) {
return -1;
}
return statusCode;
}
}