|
4 | 4 | import org.jetbrains.annotations.NotNull;
|
5 | 5 | import org.lowcoder.api.home.SessionUserService;
|
6 | 6 | import org.lowcoder.domain.application.service.ApplicationServiceImpl;
|
| 7 | +import org.lowcoder.domain.organization.model.OrgMember; |
| 8 | +import org.lowcoder.domain.organization.model.Organization; |
7 | 9 | import org.lowcoder.domain.organization.service.OrgMemberServiceImpl;
|
8 | 10 | import org.lowcoder.domain.organization.service.OrganizationService;
|
9 | 11 | import org.lowcoder.infra.constant.NewUrl;
|
@@ -49,23 +51,39 @@ private Mono<ResponseEntity<Resource>> forwardToNodeService(String applicationId
|
49 | 51 |
|
50 | 52 | String withoutLeadingSlash = path.startsWith("/") ? path.substring(1) : path;
|
51 | 53 | if(applicationId.equals("none")) {
|
52 |
| - return sessionUserService.getVisitorOrgMemberCache().flatMap(orgMember -> organizationService.getOrgCommonSettings(orgMember.getOrgId()).flatMap(organizationCommonSettings -> { |
53 |
| - Map<String, Object> config = Map.of("npmRegistries", Objects.requireNonNullElse(organizationCommonSettings.get("npmRegistries"), new ArrayList<>(0)), "workspaceId", orgMember.getOrgId()); |
54 |
| - return WebClientBuildHelper.builder() |
55 |
| - .systemProxy() |
56 |
| - .build() |
57 |
| - .post() |
58 |
| - .uri(nodeServerHelper.createUri(prefix + "/" + withoutLeadingSlash)) |
59 |
| - .contentType(MediaType.APPLICATION_JSON) |
60 |
| - .body(BodyInserters.fromValue(config)) |
61 |
| - .retrieve().toEntity(Resource.class) |
62 |
| - .map(response -> { |
63 |
| - return ResponseEntity |
64 |
| - .status(response.getStatusCode()) |
65 |
| - .headers(response.getHeaders()) |
66 |
| - .body(response.getBody()); |
67 |
| - }); |
68 |
| - })); |
| 54 | + return sessionUserService.getVisitorOrgMemberCache() |
| 55 | + .onErrorResume(e -> Mono.just(OrgMember.builder().orgId("default").build())) |
| 56 | + .flatMap(orgMember -> organizationService.getOrgCommonSettings(orgMember.getOrgId()) |
| 57 | + .onErrorResume(e -> { |
| 58 | + // Handle errors fetching organization settings and provide defaults |
| 59 | + Organization.OrganizationCommonSettings defaultSettings = new Organization.OrganizationCommonSettings(); |
| 60 | + defaultSettings.put("npmRegistries", new ArrayList<>(0)); |
| 61 | + return Mono.just(defaultSettings); |
| 62 | + }) |
| 63 | + .flatMap(organizationCommonSettings -> { |
| 64 | + Map<String, Object> config = Map.of( |
| 65 | + "npmRegistries", Objects.requireNonNullElse( |
| 66 | + organizationCommonSettings.get("npmRegistries"), |
| 67 | + new ArrayList<>(0) |
| 68 | + ), |
| 69 | + "workspaceId", orgMember.getOrgId() |
| 70 | + ); |
| 71 | + return WebClientBuildHelper.builder() |
| 72 | + .systemProxy() |
| 73 | + .build() |
| 74 | + .post() |
| 75 | + .uri(nodeServerHelper.createUri(prefix + "/" + withoutLeadingSlash)) |
| 76 | + .contentType(MediaType.APPLICATION_JSON) |
| 77 | + .body(BodyInserters.fromValue(config)) |
| 78 | + .retrieve() |
| 79 | + .toEntity(Resource.class) |
| 80 | + .map(response -> ResponseEntity |
| 81 | + .status(response.getStatusCode()) |
| 82 | + .headers(response.getHeaders()) |
| 83 | + .body(response.getBody()) |
| 84 | + ); |
| 85 | + })); |
| 86 | + |
69 | 87 | } else{
|
70 | 88 | return applicationServiceImpl.findById(applicationId).flatMap(application -> organizationService.getById(application.getOrganizationId())).flatMap(orgMember -> organizationService.getOrgCommonSettings(orgMember.getId()).flatMap(organizationCommonSettings -> {
|
71 | 89 | Map<String, Object> config = Map.of("npmRegistries", Objects.requireNonNullElse(organizationCommonSettings.get("npmRegistries"), new ArrayList<>(0)), "workspaceId", orgMember.getId());
|
|
0 commit comments