GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Added support for 403 access error and 422 path root error. · JavaScriptBach/dropbox-sdk-java@1fc5b87

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/main
    • java/com/dropbox/core
      • AccessErrorException.java
      • DbxRequestUtil.java
      • PathRootErrorException.java
    • stone
  • stone.gradle
  • stone
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/main/java/com/dropbox/core/AccessErrorException.java‎

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.dropbox.core;
2+
3+
import com.dropbox.core.v2.auth.AccessError;
4+
5+
/**
6+
* Gets thrown when invalid access occurs.
7+
*/
8+
public class AccessErrorException extends DbxException {
9+
private static final long serialVersionUID = 0;
10+
11+
private final AccessError accessError;
12+
13+
public AccessError getAccessError() {
14+
return accessError;
15+
}
16+
17+
public AccessErrorException(String requestId, String message, AccessError accessError) {
18+
super(requestId, message);
19+
this.accessError = accessError;
20+
}
21+
}
Collapse file

‎src/main/java/com/dropbox/core/DbxRequestUtil.java‎

Copy file name to clipboardExpand all lines: src/main/java/com/dropbox/core/DbxRequestUtil.java
+44-3Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.dropbox.core;
22

3+
import com.fasterxml.jackson.core.JsonProcessingException;
34
import java.io.IOException;
45
import java.io.UnsupportedEncodingException;
56
import java.net.URI;
@@ -17,6 +18,9 @@
1718
import com.dropbox.core.json.JsonReader;
1819
import com.dropbox.core.util.IOUtil;
1920
import com.dropbox.core.util.StringUtil;
21+
import com.dropbox.core.v2.auth.AccessError;
22+
import com.dropbox.core.v2.common.PathRootError;
23+
import com.dropbox.core.v2.common.PathRootError.Serializer;
2024
import com.dropbox.core.v2.callbacks.DbxGlobalCallbackFactory;
2125
import com.dropbox.core.v2.callbacks.DbxNetworkErrorCallback;
2226

@@ -278,19 +282,50 @@ public static String parseErrorBody(String requestId, int statusCode, byte[] bod
278282

279283
public static DbxException unexpectedStatus(HttpRequestor.Response response)
280284
throws NetworkIOException, BadResponseException {
281-
DbxException networkError;
282285

283286
String requestId = getRequestId(response);
284-
byte[] body = loadErrorBody(response);
285-
String message = parseErrorBody(requestId, response.getStatusCode(), body);
287+
String message = null;
288+
DbxException networkError;
286289

287290
switch (response.getStatusCode()) {
288291
case 400:
292+
message = DbxRequestUtil.messageFromResponse(response, requestId);
289293
networkError = new BadRequestException(requestId, message);
290294
break;
291295
case 401:
296+
message = DbxRequestUtil.messageFromResponse(response, requestId);
292297
networkError = new InvalidAccessTokenException(requestId, message);
293298
break;
299+
case 403:
300+
try {
301+
ApiErrorResponse<AccessError> accessErrorResponse = new ApiErrorResponse.Serializer<AccessError>(AccessError.Serializer.INSTANCE)
302+
.deserialize(response.getBody());
303+
if (accessErrorResponse.getUserMessage() != null) {
304+
message = accessErrorResponse.getUserMessage().toString();
305+
}
306+
AccessError accessError = accessErrorResponse.getError();
307+
networkError = new AccessErrorException(requestId, message, accessError);
308+
} catch (JsonProcessingException ex) {
309+
throw new BadResponseException(requestId, "Bad JSON: " + ex.getMessage(), ex);
310+
} catch (IOException ex) {
311+
throw new NetworkIOException(ex);
312+
}
313+
break;
314+
case 422:
315+
try {
316+
ApiErrorResponse<PathRootError> pathRootErrorResponse = new ApiErrorResponse.Serializer<PathRootError>(Serializer.INSTANCE)
317+
.deserialize(response.getBody());
318+
if (pathRootErrorResponse.getUserMessage() != null) {
319+
message = pathRootErrorResponse.getUserMessage().toString();
320+
}
321+
PathRootError pathRootError = pathRootErrorResponse.getError();
322+
networkError = new PathRootErrorException(requestId, message, pathRootError);
323+
} catch (JsonProcessingException ex) {
324+
throw new BadResponseException(requestId, "Bad JSON: " + ex.getMessage(), ex);
325+
} catch (IOException ex) {
326+
throw new NetworkIOException(ex);
327+
}
328+
break;
294329
case 429:
295330
try {
296331
int backoffSecs = Integer.parseInt(getFirstHeader(response, "Retry-After"));
@@ -336,6 +371,12 @@ public static DbxException unexpectedStatus(HttpRequestor.Response response)
336371
return networkError;
337372
}
338373

374+
private static String messageFromResponse(HttpRequestor.Response response, String requestId) throws NetworkIOException, BadResponseException {
375+
byte[] body = loadErrorBody(response);
376+
String message = parseErrorBody(requestId, response.getStatusCode(), body);
377+
return message;
378+
}
379+
339380
public static <T> T readJsonFromResponse(JsonReader<T> reader, HttpRequestor.Response response)
340381
throws BadResponseException, NetworkIOException {
341382
try {
Collapse file

‎src/main/java/com/dropbox/core/PathRootErrorException.java‎

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.dropbox.core;
2+
3+
import com.dropbox.core.v2.common.PathRootError;
4+
5+
/**
6+
* Gets thrown when an invalid path rood is supplied.
7+
*/
8+
public class PathRootErrorException extends DbxException {
9+
private static final long serialVersionUID = 0;
10+
11+
private final PathRootError pathRootError;
12+
13+
public PathRootError getPathRootError() {
14+
return pathRootError;
15+
}
16+
17+
public PathRootErrorException(String requestId, String message, PathRootError pathRootError) {
18+
super(requestId, message);
19+
this.pathRootError = pathRootError;
20+
}
21+
}
Collapse file

‎src/main/stone‎

Copy file name to clipboard
Submodule stone updated 18 files
  • auth.stone
    +5
  • common.stone
    +43
  • files.stone
    +94
    -17
  • files_properties.stone
    +8
  • paper.stone
    +28
    -29
  • shared_content_links.stone
    +30
  • shared_links.stone
    +8
  • sharing_files.stone
    +46
    -18
  • sharing_folders.stone
    +26
    -17
  • stone_cfg.stone
    +6
    -1
  • team.stone
    +104
    -3
  • team_devices.stone
    +3
  • team_folders.stone
    +33
    -2
  • team_log.stone
    +90
  • team_log_generated.stone
    +4.3k
  • team_members.stone
    +2
    -2
  • users.stone
    +12
    -23
  • users_common.stone
    +20
Collapse file

‎stone‎

Copy file name to clipboard
Submodule stone updated 3 files
  • stone/target/swift_helpers.py
    +1
  • stone/target/swift_rsrc/jazzy.json
    -38
  • stone/target/swift_types.py
    +4
    -3
Collapse file

‎stone.gradle‎

Copy file name to clipboardExpand all lines: stone.gradle
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class ClientSpec {
1313
String javadoc = null
1414
String routeFilter = null
1515
String requestsClassnamePrefix = null
16+
String unusedClassesToGenerate = null
1617
}
1718

1819
def runStoneGenerator(StoneConfig config,
@@ -57,7 +58,6 @@ def runStoneGenerator(StoneConfig config,
5758
return
5859
}
5960

60-
def firstClient = true;
6161
for (int i = 0; i < config.clients.size; ++i) {
6262
def client = config.clients[i]
6363
def isFirst = i == 0
@@ -97,6 +97,9 @@ def runStoneGenerator(StoneConfig config,
9797
if (client.requestsClassnamePrefix != null) {
9898
args "--requests-classname-prefix", client.requestsClassnamePrefix
9999
}
100+
if (client.unusedClassesToGenerate != null) {
101+
args "--unused-classes-to-generate", client.unusedClassesToGenerate
102+
}
100103
}
101104
}
102105
}
@@ -140,6 +143,7 @@ project.sourceSets.all { SourceSet sourceSet ->
140143

141144

142145
generateStone {
146+
String unusedClassesToGenerate = 'PathRootError, AccessError, RateLimitError'
143147
config = new StoneConfig(
144148
packageName: 'com.dropbox.core.v2',
145149
globalRouteFilter: 'alpha_group=null and beta_group=null',
@@ -150,6 +154,7 @@ generateStone {
150154
javadoc: 'Base class for user auth clients.',
151155
requestsClassnamePrefix: "DbxUser",
152156
routeFilter: 'auth="user" or auth="noauth"',
157+
unusedClassesToGenerate: unusedClassesToGenerate,
153158
),
154159
new ClientSpec(
155160
name: 'DbxTeamClientV2Base',

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.