-
Notifications
You must be signed in to change notification settings - Fork 156
Expand file tree
/
Copy pathMsalServiceException.java
More file actions
130 lines (111 loc) · 4.33 KB
/
MsalServiceException.java
File metadata and controls
130 lines (111 loc) · 4.33 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.microsoft.aad.msal4j;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* Exception type thrown when service returns an error response or other networking errors occur.
*/
public class MsalServiceException extends MsalException {
private Integer statusCode;
private String statusMessage;
private String claims;
private Map<String, List<String>> headers;
private String managedIdentitySource;
private String subError;
/**
* Initializes a new instance of the exception class with a specified error message
*
* @param message the error message that explains the reason for the exception
* @param error a simplified error code from {@link AuthenticationErrorCode} and used for references in documentation
*/
public MsalServiceException(final String message, final String error) {
super(message, error);
}
/**
* Initializes a new instance of the exception class with a specified error message and correlation ID
*
* @param message the error message that explains the reason for the exception
* @param error a simplified error code from {@link AuthenticationErrorCode} and used for references in documentation
* @param correlationId the correlation ID for request tracking
*/
public MsalServiceException(final String message, final String error, final String correlationId) {
super(message, error, correlationId);
}
/**
* Initializes a new instance of the exception class
*
* @param errorResponse response object contain information about error returned by server
* @param httpHeaders http headers from the server response
*/
public MsalServiceException(
final ErrorResponse errorResponse,
final Map<String, List<String>> httpHeaders) {
super(errorResponse.errorDescription, errorResponse.error(), errorResponse.correlation_id());
this.statusCode = errorResponse.statusCode();
this.statusMessage = errorResponse.statusMessage();
this.subError = errorResponse.subError();
this.claims = errorResponse.claims();
this.headers = Collections.unmodifiableMap(httpHeaders);
}
/**
* Initializes a new instance of the exception class, with any extra properties for a Managed Identity error
*
* @param message the error message that explains the reason for the exception
* @param managedIdentitySource the Managed Identity service
*/
public MsalServiceException(
final String message, final String error,
ManagedIdentitySourceType managedIdentitySource) {
this(message, error); //Call the more common constructor to set the error message properties
this.managedIdentitySource = managedIdentitySource.name();
}
/**
* Initializes a new instance of the exception class
*
* @param discoveryResponse response object from instance discovery network call
*/
public MsalServiceException(final AadInstanceDiscoveryResponse discoveryResponse) {
super(discoveryResponse.errorDescription(), discoveryResponse.error(), discoveryResponse.correlationId());
}
/**
* Status code returned from http layer
*/
public Integer statusCode() {
return this.statusCode;
}
/**
* Status message returned from the http layer
*/
public String statusMessage() {
return this.statusMessage;
}
/**
* An ID that can be used to piece up a single authentication flow.
*/
@Override
public String correlationId() {
return super.correlationId();
}
/**
* Claims included in the claims challenge
*/
public String claims() {
return this.claims;
}
/**
* Contains the http headers from the server response that indicated an error.
* When the server returns a 429 Too Many Requests error, a Retry-After should be set.
* It is important to read and respect the time specified in the Retry-After header
*/
public Map<String, List<String>> headers() {
return this.headers;
}
public String managedIdentitySource() {
return this.managedIdentitySource;
}
String subError() {
return this.subError;
}
}