Commit 70ba8a8
authored
Fix error type for non-JSON error responses (#758)
## Summary
When the server returns a plain-text error response (e.g. `"Invalid
Token"` with HTTP 403), the SDK throws `Unknown` instead of
`PermissionDenied`.
The root cause: `parseUnknownError` derives an error code by splitting
`response.getStatus()` on space, expecting `"403 Forbidden"`. But
`CommonsHttpClient` passes `statusLine.getReasonPhrase()`, which is just
`"Forbidden"`. The split produces one element, so error code defaults to
`"UNKNOWN"`, which matches `ErrorMapper`'s error code mapping and
short-circuits the status code mapping that would have correctly
produced `PermissionDenied`.
The fix removes the error code derivation entirely. Leaving `errorCode`
null lets `AbstractErrorMapper.apply` skip the error code mapping and
fall through to the status code mapping (403 -> `PermissionDenied`, 401
-> `Unauthenticated`, etc.). The error message now uses the raw response
body instead of appending Jackson parse exception details.
**Behavioral change**: non-JSON error responses now produce typed
exceptions based on HTTP status code instead of always producing
`Unknown`. The error message no longer contains Jackson deserialization
internals.
## Test plan
- [x] New `PlainTextErrorTest` covers: plain-text 403/401/404, HTML
`<pre>` extraction, empty body, null body
- [x] Full test suite passes (`mvn test -pl databricks-sdk-java`)1 parent 89297b1 commit 70ba8a8
File tree
3 files changed
+71
-14
lines changed- databricks-sdk-java/src
- main/java/com/databricks/sdk/core/error
- test/java/com/databricks/sdk/core/error
3 files changed
+71
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
Lines changed: 5 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
119 | | - | |
| 119 | + | |
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
| 123 | + | |
124 | 124 | | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
| 125 | + | |
133 | 126 | | |
134 | 127 | | |
135 | | - | |
| 128 | + | |
136 | 129 | | |
137 | | - | |
138 | | - | |
139 | | - | |
| 130 | + | |
140 | 131 | | |
141 | 132 | | |
142 | 133 | | |
| |||
Lines changed: 65 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments