-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDeepgramApiException.java
More file actions
73 lines (63 loc) · 1.86 KB
/
DeepgramApiException.java
File metadata and controls
73 lines (63 loc) · 1.86 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
/**
* This file was auto-generated by Fern from our API Definition.
*/
package com.deepgram.core;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import okhttp3.Response;
/**
* This exception type will be thrown for any non-2XX API responses.
*/
public class DeepgramApiException extends DeepgramApiException {
/**
* The error code of the response that triggered the exception.
*/
private final int statusCode;
/**
* The body of the response that triggered the exception.
*/
private final Object body;
private final Map<String, List<String>> headers;
public DeepgramApiException(String message, int statusCode, Object body) {
super(message);
this.statusCode = statusCode;
this.body = body;
this.headers = new HashMap<>();
}
public DeepgramApiException(String message, int statusCode, Object body, Response rawResponse) {
super(message);
this.statusCode = statusCode;
this.body = body;
this.headers = new HashMap<>();
rawResponse.headers().forEach(header -> {
String key = header.component1();
String value = header.component2();
this.headers.computeIfAbsent(key, _str -> new ArrayList<>()).add(value);
});
}
/**
* @return the statusCode
*/
public int statusCode() {
return this.statusCode;
}
/**
* @return the body
*/
public Object body() {
return this.body;
}
/**
* @return the headers
*/
public Map<String, List<String>> headers() {
return this.headers;
}
@Override
public String toString() {
return "DeepgramApiException{" + "message: " + getMessage() + ", statusCode: " + statusCode + ", body: "
+ ObjectMappers.stringify(body) + "}";
}
}