chore(core): better doc action error message (#10288)

This commit is contained in:
forehalo
2025-02-19 10:38:38 +00:00
parent 54b7515167
commit 02f567f2c0
13 changed files with 74 additions and 72 deletions

View File

@@ -419,11 +419,11 @@ export const USER_FRIENDLY_ERRORS = {
message: ({ spaceId, docId }) =>
`Doc ${docId} under Space ${spaceId} not found.`,
},
doc_access_denied: {
doc_action_denied: {
type: 'no_permission',
args: { spaceId: 'string', docId: 'string' },
message: ({ spaceId, docId }) =>
`You do not have permission to access doc ${docId} under Space ${spaceId}.`,
args: { spaceId: 'string', docId: 'string', action: 'string' },
message: ({ docId, action }) =>
`You do not have permission to perform ${action} action on doc ${docId}.`,
},
version_rejected: {
type: 'action_forbidden',

View File

@@ -299,14 +299,15 @@ export class DocNotFound extends UserFriendlyError {
}
}
@ObjectType()
class DocAccessDeniedDataType {
class DocActionDeniedDataType {
@Field() spaceId!: string
@Field() docId!: string
@Field() action!: string
}
export class DocAccessDenied extends UserFriendlyError {
constructor(args: DocAccessDeniedDataType, message?: string | ((args: DocAccessDeniedDataType) => string)) {
super('no_permission', 'doc_access_denied', message, args);
export class DocActionDenied extends UserFriendlyError {
constructor(args: DocActionDeniedDataType, message?: string | ((args: DocActionDeniedDataType) => string)) {
super('no_permission', 'doc_action_denied', message, args);
}
}
@ObjectType()
@@ -832,7 +833,7 @@ export enum ErrorNames {
SPACE_OWNER_NOT_FOUND,
SPACE_SHOULD_HAVE_ONLY_ONE_OWNER,
DOC_NOT_FOUND,
DOC_ACCESS_DENIED,
DOC_ACTION_DENIED,
VERSION_REJECTED,
INVALID_HISTORY_TIMESTAMP,
DOC_HISTORY_NOT_FOUND,
@@ -903,5 +904,5 @@ registerEnumType(ErrorNames, {
export const ErrorDataUnionType = createUnionType({
name: 'ErrorDataUnion',
types: () =>
[GraphqlBadRequestDataType, QueryTooLongDataType, WrongSignInCredentialsDataType, UnknownOauthProviderDataType, MissingOauthQueryParameterDataType, InvalidEmailDataType, InvalidPasswordLengthDataType, WorkspacePermissionNotFoundDataType, SpaceNotFoundDataType, MemberNotFoundInSpaceDataType, NotInSpaceDataType, AlreadyInSpaceDataType, SpaceAccessDeniedDataType, SpaceOwnerNotFoundDataType, SpaceShouldHaveOnlyOneOwnerDataType, DocNotFoundDataType, DocAccessDeniedDataType, VersionRejectedDataType, InvalidHistoryTimestampDataType, DocHistoryNotFoundDataType, BlobNotFoundDataType, ExpectToGrantDocUserRolesDataType, ExpectToRevokeDocUserRolesDataType, ExpectToUpdateDocUserRoleDataType, UnsupportedSubscriptionPlanDataType, SubscriptionAlreadyExistsDataType, SubscriptionNotExistsDataType, SameSubscriptionRecurringDataType, SubscriptionPlanNotFoundDataType, CopilotDocNotFoundDataType, CopilotMessageNotFoundDataType, CopilotPromptNotFoundDataType, CopilotProviderSideErrorDataType, CopilotInvalidContextDataType, CopilotContextFileNotSupportedDataType, CopilotFailedToModifyContextDataType, CopilotFailedToMatchContextDataType, RuntimeConfigNotFoundDataType, InvalidRuntimeConfigTypeDataType, InvalidLicenseUpdateParamsDataType, WorkspaceMembersExceedLimitToDowngradeDataType] as const,
[GraphqlBadRequestDataType, QueryTooLongDataType, WrongSignInCredentialsDataType, UnknownOauthProviderDataType, MissingOauthQueryParameterDataType, InvalidEmailDataType, InvalidPasswordLengthDataType, WorkspacePermissionNotFoundDataType, SpaceNotFoundDataType, MemberNotFoundInSpaceDataType, NotInSpaceDataType, AlreadyInSpaceDataType, SpaceAccessDeniedDataType, SpaceOwnerNotFoundDataType, SpaceShouldHaveOnlyOneOwnerDataType, DocNotFoundDataType, DocActionDeniedDataType, VersionRejectedDataType, InvalidHistoryTimestampDataType, DocHistoryNotFoundDataType, BlobNotFoundDataType, ExpectToGrantDocUserRolesDataType, ExpectToRevokeDocUserRolesDataType, ExpectToUpdateDocUserRoleDataType, UnsupportedSubscriptionPlanDataType, SubscriptionAlreadyExistsDataType, SubscriptionNotExistsDataType, SameSubscriptionRecurringDataType, SubscriptionPlanNotFoundDataType, CopilotDocNotFoundDataType, CopilotMessageNotFoundDataType, CopilotPromptNotFoundDataType, CopilotProviderSideErrorDataType, CopilotInvalidContextDataType, CopilotContextFileNotSupportedDataType, CopilotFailedToModifyContextDataType, CopilotFailedToMatchContextDataType, RuntimeConfigNotFoundDataType, InvalidRuntimeConfigTypeDataType, InvalidLicenseUpdateParamsDataType, WorkspaceMembersExceedLimitToDowngradeDataType] as const,
});