mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 13:25:12 +00:00
chore(server): filter out some logs (#9059)
This commit is contained in:
@@ -184,7 +184,7 @@ export class UserService {
|
||||
const user = await this.findUserWithHashedPasswordByEmail(email);
|
||||
|
||||
if (!user) {
|
||||
throw new WrongSignInCredentials();
|
||||
throw new WrongSignInCredentials({ email });
|
||||
}
|
||||
|
||||
if (!user.password) {
|
||||
@@ -197,7 +197,7 @@ export class UserService {
|
||||
);
|
||||
|
||||
if (!passwordMatches) {
|
||||
throw new WrongSignInCredentials();
|
||||
throw new WrongSignInCredentials({ email });
|
||||
}
|
||||
|
||||
return user;
|
||||
|
||||
@@ -37,6 +37,25 @@ const BaseTypeToHttpStatusMap: Record<UserFriendlyErrorBaseType, HttpStatus> = {
|
||||
internal_server_error: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
};
|
||||
|
||||
const IncludedEvents = new Set([
|
||||
// email
|
||||
'invalid_email',
|
||||
'email_token_not_found',
|
||||
'invalid_email_token',
|
||||
'email_already_used',
|
||||
'same_email_provided',
|
||||
// magic link
|
||||
'action_forbidden',
|
||||
'link_expired',
|
||||
'email_verification_required',
|
||||
// oauth
|
||||
'missing_oauth_query_parameter',
|
||||
'unknown_oauth_provider',
|
||||
'invalid_oauth_callback_state',
|
||||
'oauth_state_expired',
|
||||
'oauth_account_already_connected',
|
||||
]);
|
||||
|
||||
export class UserFriendlyError extends Error {
|
||||
/**
|
||||
* Standard HTTP status code
|
||||
@@ -100,13 +119,11 @@ export class UserFriendlyError extends Error {
|
||||
|
||||
log(context: string) {
|
||||
// ignore all user behavior error log
|
||||
if (this.type !== 'internal_server_error') {
|
||||
// always record auth related error
|
||||
const isAuthError =
|
||||
typeof this.stack === 'string' &&
|
||||
(this.stack.includes('/core/auth/') ||
|
||||
this.stack.includes('/plugins/oauth/'));
|
||||
if (!isAuthError) return;
|
||||
if (
|
||||
this.type !== 'internal_server_error' &&
|
||||
!IncludedEvents.has(this.name)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
new Logger(context).error(
|
||||
@@ -239,7 +256,8 @@ export const USER_FRIENDLY_ERRORS = {
|
||||
},
|
||||
wrong_sign_in_credentials: {
|
||||
type: 'invalid_input',
|
||||
message: 'Wrong user email or password.',
|
||||
args: { email: 'string' },
|
||||
message: ({ email }) => `Wrong user email or password: ${email}`,
|
||||
},
|
||||
unknown_oauth_provider: {
|
||||
type: 'invalid_input',
|
||||
|
||||
@@ -45,10 +45,14 @@ export class SameEmailProvided extends UserFriendlyError {
|
||||
super('invalid_input', 'same_email_provided', message);
|
||||
}
|
||||
}
|
||||
@ObjectType()
|
||||
class WrongSignInCredentialsDataType {
|
||||
@Field() email!: string
|
||||
}
|
||||
|
||||
export class WrongSignInCredentials extends UserFriendlyError {
|
||||
constructor(message?: string) {
|
||||
super('invalid_input', 'wrong_sign_in_credentials', message);
|
||||
constructor(args: WrongSignInCredentialsDataType, message?: string | ((args: WrongSignInCredentialsDataType) => string)) {
|
||||
super('invalid_input', 'wrong_sign_in_credentials', message, args);
|
||||
}
|
||||
}
|
||||
@ObjectType()
|
||||
@@ -670,5 +674,5 @@ registerEnumType(ErrorNames, {
|
||||
export const ErrorDataUnionType = createUnionType({
|
||||
name: 'ErrorDataUnion',
|
||||
types: () =>
|
||||
[UnknownOauthProviderDataType, MissingOauthQueryParameterDataType, InvalidEmailDataType, InvalidPasswordLengthDataType, SpaceNotFoundDataType, NotInSpaceDataType, AlreadyInSpaceDataType, SpaceAccessDeniedDataType, SpaceOwnerNotFoundDataType, DocNotFoundDataType, DocAccessDeniedDataType, VersionRejectedDataType, InvalidHistoryTimestampDataType, DocHistoryNotFoundDataType, BlobNotFoundDataType, UnsupportedSubscriptionPlanDataType, SubscriptionAlreadyExistsDataType, SubscriptionNotExistsDataType, SameSubscriptionRecurringDataType, SubscriptionPlanNotFoundDataType, CopilotMessageNotFoundDataType, CopilotPromptNotFoundDataType, CopilotProviderSideErrorDataType, RuntimeConfigNotFoundDataType, InvalidRuntimeConfigTypeDataType] as const,
|
||||
[WrongSignInCredentialsDataType, UnknownOauthProviderDataType, MissingOauthQueryParameterDataType, InvalidEmailDataType, InvalidPasswordLengthDataType, SpaceNotFoundDataType, NotInSpaceDataType, AlreadyInSpaceDataType, SpaceAccessDeniedDataType, SpaceOwnerNotFoundDataType, DocNotFoundDataType, DocAccessDeniedDataType, VersionRejectedDataType, InvalidHistoryTimestampDataType, DocHistoryNotFoundDataType, BlobNotFoundDataType, UnsupportedSubscriptionPlanDataType, SubscriptionAlreadyExistsDataType, SubscriptionNotExistsDataType, SameSubscriptionRecurringDataType, SubscriptionPlanNotFoundDataType, CopilotMessageNotFoundDataType, CopilotPromptNotFoundDataType, CopilotProviderSideErrorDataType, RuntimeConfigNotFoundDataType, InvalidRuntimeConfigTypeDataType] as const,
|
||||
});
|
||||
|
||||
@@ -209,7 +209,7 @@ type EditorType {
|
||||
name: String!
|
||||
}
|
||||
|
||||
union ErrorDataUnion = AlreadyInSpaceDataType | BlobNotFoundDataType | CopilotMessageNotFoundDataType | CopilotPromptNotFoundDataType | CopilotProviderSideErrorDataType | DocAccessDeniedDataType | DocHistoryNotFoundDataType | DocNotFoundDataType | InvalidEmailDataType | InvalidHistoryTimestampDataType | InvalidPasswordLengthDataType | InvalidRuntimeConfigTypeDataType | MissingOauthQueryParameterDataType | NotInSpaceDataType | RuntimeConfigNotFoundDataType | SameSubscriptionRecurringDataType | SpaceAccessDeniedDataType | SpaceNotFoundDataType | SpaceOwnerNotFoundDataType | SubscriptionAlreadyExistsDataType | SubscriptionNotExistsDataType | SubscriptionPlanNotFoundDataType | UnknownOauthProviderDataType | UnsupportedSubscriptionPlanDataType | VersionRejectedDataType
|
||||
union ErrorDataUnion = AlreadyInSpaceDataType | BlobNotFoundDataType | CopilotMessageNotFoundDataType | CopilotPromptNotFoundDataType | CopilotProviderSideErrorDataType | DocAccessDeniedDataType | DocHistoryNotFoundDataType | DocNotFoundDataType | InvalidEmailDataType | InvalidHistoryTimestampDataType | InvalidPasswordLengthDataType | InvalidRuntimeConfigTypeDataType | MissingOauthQueryParameterDataType | NotInSpaceDataType | RuntimeConfigNotFoundDataType | SameSubscriptionRecurringDataType | SpaceAccessDeniedDataType | SpaceNotFoundDataType | SpaceOwnerNotFoundDataType | SubscriptionAlreadyExistsDataType | SubscriptionNotExistsDataType | SubscriptionPlanNotFoundDataType | UnknownOauthProviderDataType | UnsupportedSubscriptionPlanDataType | VersionRejectedDataType | WrongSignInCredentialsDataType
|
||||
|
||||
enum ErrorNames {
|
||||
ACCESS_DENIED
|
||||
@@ -1048,6 +1048,10 @@ type WorkspaceType {
|
||||
team: Boolean!
|
||||
}
|
||||
|
||||
type WrongSignInCredentialsDataType {
|
||||
email: String!
|
||||
}
|
||||
|
||||
type tokenType {
|
||||
refresh: String!
|
||||
sessionToken: String
|
||||
|
||||
Reference in New Issue
Block a user