Skip to content

Commit

Permalink
add try catch
Browse files Browse the repository at this point in the history
Signed-off-by: Qxisylolo <[email protected]>
  • Loading branch information
Qxisylolo committed Nov 28, 2024
1 parent 357c833 commit d5fb789
Showing 1 changed file with 40 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -505,48 +505,65 @@ export class WorkspaceSavedObjectsClientWrapper {
let flag = true;
const processedObjects = await Promise.all(
objectToBulkGet.saved_objects.map(async (object) => {
if (validateIsWorkspaceDataSourceAndConnectionObjectType(object.type)) {
const hasPermission = this.validateDataSourcePermissions(
object,
wrapperOptions.request
);
if (!hasPermission) {
try {
if (validateIsWorkspaceDataSourceAndConnectionObjectType(object.type)) {
const hasPermission = this.validateDataSourcePermissions(
object,
wrapperOptions.request
);
if (!hasPermission) {
flag = false;
ACLAuditor?.increment(ACLAuditorStateKey.VALIDATE_FAILURE, 1);
return {
...object,
workspaces: [],
attributes: {} as T,
error: {
...generateDataSourcePermissionError().output.payload,
statusCode: 403,
},
};
}
}

if (
!(await this.validateWorkspacesAndSavedObjectsPermissions(
object,
wrapperOptions.request,
[WorkspacePermissionMode.LibraryRead, WorkspacePermissionMode.LibraryWrite],
[WorkspacePermissionMode.Write, WorkspacePermissionMode.Read],
false
))
) {
flag = false;
ACLAuditor?.increment(ACLAuditorStateKey.VALIDATE_FAILURE, 1);
return {
...object,
workspaces: [],
attributes: {} as T,
error: {
...generateDataSourcePermissionError().output.payload,
...generateSavedObjectsPermissionError().output.payload,
statusCode: 403,
},
};
}
}

if (
!(await this.validateWorkspacesAndSavedObjectsPermissions(
object,
wrapperOptions.request,
[WorkspacePermissionMode.LibraryRead, WorkspacePermissionMode.LibraryWrite],
[WorkspacePermissionMode.Write, WorkspacePermissionMode.Read],
false
))
) {
return object;
} catch (error) {
flag = false;

Check warning on line 552 in src/plugins/workspace/server/saved_objects/workspace_saved_objects_client_wrapper.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/workspace/server/saved_objects/workspace_saved_objects_client_wrapper.ts#L552

Added line #L552 was not covered by tests
ACLAuditor?.increment(ACLAuditorStateKey.VALIDATE_FAILURE, 1);

const formattedError = {

Check warning on line 555 in src/plugins/workspace/server/saved_objects/workspace_saved_objects_client_wrapper.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/workspace/server/saved_objects/workspace_saved_objects_client_wrapper.ts#L555

Added line #L555 was not covered by tests
message: error?.message || 'unexpected error',
error: error?.error,
statusCode: error.statusCode,
};
return {

Check warning on line 560 in src/plugins/workspace/server/saved_objects/workspace_saved_objects_client_wrapper.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/workspace/server/saved_objects/workspace_saved_objects_client_wrapper.ts#L560

Added line #L560 was not covered by tests
...object,
workspaces: [],
attributes: {} as T,
error: {
...generateSavedObjectsPermissionError().output.payload,
statusCode: 403,
},
error: formattedError,
};
}
return object;
})
);

Expand Down

0 comments on commit d5fb789

Please sign in to comment.