-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBankIdApiUnexpectedResponseException.java
More file actions
76 lines (67 loc) · 3.04 KB
/
BankIdApiUnexpectedResponseException.java
File metadata and controls
76 lines (67 loc) · 3.04 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
package dev.eidentification.bankid.exceptions;
import org.jspecify.annotations.Nullable;
import java.net.http.HttpResponse;
/**
* This class represents a specific exception to be used
* when an unexpected API response is received in the interaction
* with the BankId system. It extends {@link BankIdException} class
* and inherits its behavior.
* <p>
* The class will store and provide the {@link HttpResponse.ResponseInfo}
* and the {@link String} representation of the response body
* for debug and error diagnosis.
*
* @see BankIdException
*/
public final class BankIdApiUnexpectedResponseException extends BankIdException {
private final HttpResponse.ResponseInfo responseInfo;
private final String responseBody;
private BankIdApiUnexpectedResponseException(final HttpResponse.ResponseInfo responseInfo, final String responseBody) {
super("BankId API returned an unexpected response. Body: " + responseBody);
this.responseInfo = responseInfo;
this.responseBody = responseBody;
}
private BankIdApiUnexpectedResponseException(final HttpResponse.ResponseInfo responseInfo, final String responseBody, @Nullable final Throwable cause) {
super("BankId API returned an unexpected response. Body: " + responseBody, cause);
this.responseInfo = responseInfo;
this.responseBody = responseBody;
}
/**
* Creates a new instance of BankIdApiUnexpectedResponseException.
*
* @param responseInfo The response information associated with the exception.
* @param responseBody The response body associated with the exception.
* @param cause The cause of the exception.
* @return A new instance of BankIdApiUnexpectedResponseException.
*/
public static BankIdApiUnexpectedResponseException of(final HttpResponse.ResponseInfo responseInfo, final String responseBody,
@Nullable final Throwable cause) {
return new BankIdApiUnexpectedResponseException(responseInfo, responseBody, cause);
}
/**
* Creates a new instance of BankIdApiUnexpectedResponseException.
*
* @param responseInfo The response information associated with the exception.
* @param responseBody The response body associated with the exception.
* @return A new instance of BankIdApiUnexpectedResponseException.
*/
public static BankIdApiUnexpectedResponseException of(final HttpResponse.ResponseInfo responseInfo, final String responseBody) {
return new BankIdApiUnexpectedResponseException(responseInfo, responseBody);
}
/**
* Retrieves the response information associated with an exception thrown during interaction with the BankId system.
*
* @return The response information.
*/
public HttpResponse.ResponseInfo getResponseInfo() {
return this.responseInfo;
}
/**
* Retrieves the response body associated with the exception.
*
* @return The response body.
*/
public String getResponseBody() {
return this.responseBody;
}
}