|
18 | 18 | import io.swagger.v3.oas.annotations.media.Schema; |
19 | 19 | import io.swagger.v3.oas.annotations.responses.ApiResponse; |
20 | 20 | import jakarta.servlet.http.HttpServletRequest; |
| 21 | +import org.eclipse.openvsx.util.ErrorResultException; |
21 | 22 | import org.eclipse.openvsx.util.NotFoundException; |
22 | 23 | import org.eclipse.openvsx.util.TargetPlatform; |
23 | 24 | import org.eclipse.openvsx.util.UrlUtil; |
| 25 | +import org.slf4j.Logger; |
| 26 | +import org.slf4j.LoggerFactory; |
24 | 27 | import org.springframework.http.CacheControl; |
25 | 28 | import org.springframework.http.HttpStatus; |
26 | 29 | import org.springframework.http.MediaType; |
|
44 | 47 | public class VSCodeAPI { |
45 | 48 |
|
46 | 49 | private static final int DEFAULT_PAGE_SIZE = 20; |
| 50 | + private static final Logger logger = LoggerFactory.getLogger(VSCodeAPI.class); |
47 | 51 |
|
48 | 52 | private final LocalVSCodeService local; |
49 | 53 | private final UpstreamVSCodeService upstream; |
@@ -81,7 +85,7 @@ private Iterable<IVSCodeService> getVSCodeServices() { |
81 | 85 | public ExtensionQueryResult extensionQuery(@RequestBody @Parameter(description = "Parameters of the extension query") ExtensionQueryParam param) { |
82 | 86 | var size = 0; |
83 | 87 | if(param.filters() != null && !param.filters().isEmpty()) { |
84 | | - size = param.filters().get(0).pageSize(); |
| 88 | + size = param.filters().getFirst().pageSize(); |
85 | 89 | } |
86 | 90 | if(size <= 0) { |
87 | 91 | size = DEFAULT_PAGE_SIZE; |
@@ -149,15 +153,19 @@ public ResponseEntity<StreamingResponseBody> getAsset( |
149 | 153 | String targetPlatform |
150 | 154 | ) { |
151 | 155 | var restOfTheUrl = UrlUtil.extractWildcardPath(request); |
152 | | - for (var service : getVSCodeServices()) { |
153 | | - try { |
154 | | - return service.getAsset(namespaceName, extensionName, version, assetType, targetPlatform, restOfTheUrl); |
155 | | - } catch (NotFoundException exc) { |
156 | | - // Try the next registry |
| 156 | + try { |
| 157 | + for (var service : getVSCodeServices()) { |
| 158 | + try { |
| 159 | + return service.getAsset(namespaceName, extensionName, version, assetType, targetPlatform, restOfTheUrl); |
| 160 | + } catch (NotFoundException exc) { |
| 161 | + // Try the next registry |
| 162 | + } |
157 | 163 | } |
| 164 | + return ResponseEntity.notFound().build(); |
| 165 | + } catch (ErrorResultException ex) { |
| 166 | + logger.error(ex.getMessage()); |
| 167 | + return ResponseEntity.internalServerError().build(); |
158 | 168 | } |
159 | | - |
160 | | - return ResponseEntity.notFound().build(); |
161 | 169 | } |
162 | 170 |
|
163 | 171 | @GetMapping("/vscode/item") |
@@ -301,15 +309,19 @@ public ResponseEntity<StreamingResponseBody> browse( |
301 | 309 | @PathVariable @Parameter(description = "Extension version", example = "0.3.1710435722") String version |
302 | 310 | ) { |
303 | 311 | var path = UrlUtil.extractWildcardPath(request); |
304 | | - for (var service : getVSCodeServices()) { |
305 | | - try { |
306 | | - return service.browse(namespaceName, extensionName, version, path); |
307 | | - } catch (NotFoundException exc) { |
308 | | - // Try the next registry |
| 312 | + try { |
| 313 | + for (var service : getVSCodeServices()) { |
| 314 | + try { |
| 315 | + return service.browse(namespaceName, extensionName, version, path); |
| 316 | + } catch (NotFoundException exc) { |
| 317 | + // Try the next registry |
| 318 | + } |
309 | 319 | } |
| 320 | + return ResponseEntity.notFound().build(); |
| 321 | + } catch (ErrorResultException ex) { |
| 322 | + logger.error(ex.getMessage()); |
| 323 | + return ResponseEntity.internalServerError().build(); |
310 | 324 | } |
311 | | - |
312 | | - return ResponseEntity.notFound().build(); |
313 | 325 | } |
314 | 326 |
|
315 | 327 | @GetMapping( |
@@ -339,9 +351,9 @@ public ResponseEntity<ExtensionQueryResult.Extension> getLatest( |
339 | 351 | var result = extensionQueryRequestHandler.getResult(param, 1, DEFAULT_PAGE_SIZE); |
340 | 352 | var extension = Optional.of(result) |
341 | 353 | .filter(r -> !r.results().isEmpty()) |
342 | | - .map(r -> r.results().get(0).extensions()) |
| 354 | + .map(r -> r.results().getFirst().extensions()) |
343 | 355 | .filter(e -> !e.isEmpty()) |
344 | | - .map(e -> e.get(0)) |
| 356 | + .map(List::getFirst) |
345 | 357 | .orElse(null); |
346 | 358 |
|
347 | 359 | return extension != null |
|
0 commit comments