@@ -1,3 +1,5 @@
|
|||||||
|
import type { UserFriendlyError } from '@affine/graphql';
|
||||||
|
|
||||||
export class NetworkError extends Error {
|
export class NetworkError extends Error {
|
||||||
constructor(
|
constructor(
|
||||||
public readonly originError: Error,
|
public readonly originError: Error,
|
||||||
@@ -14,7 +16,7 @@ export function isNetworkError(error: Error): error is NetworkError {
|
|||||||
|
|
||||||
export class BackendError extends Error {
|
export class BackendError extends Error {
|
||||||
constructor(
|
constructor(
|
||||||
public readonly originError: Error,
|
public readonly originError: UserFriendlyError,
|
||||||
public readonly status?: number
|
public readonly status?: number
|
||||||
) {
|
) {
|
||||||
super(`Server error: ${originError.message}`);
|
super(`Server error: ${originError.message}`);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { distinctUntilChanged, map, skip } from 'rxjs';
|
|||||||
|
|
||||||
import type { UrlService } from '../../url';
|
import type { UrlService } from '../../url';
|
||||||
import { type AuthAccountInfo, AuthSession } from '../entities/session';
|
import { type AuthAccountInfo, AuthSession } from '../entities/session';
|
||||||
|
import { BackendError } from '../error';
|
||||||
import type { AuthStore } from '../stores/auth';
|
import type { AuthStore } from '../stores/auth';
|
||||||
import type { FetchService } from './fetch';
|
import type { FetchService } from './fetch';
|
||||||
|
|
||||||
@@ -111,7 +112,10 @@ export class AuthService extends Service {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
track.$.$.auth.signInFail({ method: 'magic-link' });
|
track.$.$.auth.signInFail({
|
||||||
|
method: 'magic-link',
|
||||||
|
reason: e instanceof BackendError ? e.originError.type : 'unknown',
|
||||||
|
});
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,7 +133,10 @@ export class AuthService extends Service {
|
|||||||
this.session.revalidate();
|
this.session.revalidate();
|
||||||
track.$.$.auth.signedIn({ method: 'magic-link' });
|
track.$.$.auth.signedIn({ method: 'magic-link' });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
track.$.$.auth.signInFail({ method: 'magic-link' });
|
track.$.$.auth.signInFail({
|
||||||
|
method: 'magic-link',
|
||||||
|
reason: e instanceof BackendError ? e.originError.type : 'unknown',
|
||||||
|
});
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -166,7 +173,11 @@ export class AuthService extends Service {
|
|||||||
|
|
||||||
return url;
|
return url;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
track.$.$.auth.signInFail({ method: 'oauth', provider });
|
track.$.$.auth.signInFail({
|
||||||
|
method: 'oauth',
|
||||||
|
provider,
|
||||||
|
reason: e instanceof BackendError ? e.originError.type : 'unknown',
|
||||||
|
});
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,7 +197,11 @@ export class AuthService extends Service {
|
|||||||
track.$.$.auth.signedIn({ method: 'oauth', provider });
|
track.$.$.auth.signedIn({ method: 'oauth', provider });
|
||||||
return res.json();
|
return res.json();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
track.$.$.auth.signInFail({ method: 'oauth', provider });
|
track.$.$.auth.signInFail({
|
||||||
|
method: 'oauth',
|
||||||
|
provider,
|
||||||
|
reason: e instanceof BackendError ? e.originError.type : 'unknown',
|
||||||
|
});
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -212,7 +227,10 @@ export class AuthService extends Service {
|
|||||||
this.session.revalidate();
|
this.session.revalidate();
|
||||||
track.$.$.auth.signedIn({ method: 'password' });
|
track.$.$.auth.signedIn({ method: 'password' });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
track.$.$.auth.signInFail({ method: 'password' });
|
track.$.$.auth.signInFail({
|
||||||
|
method: 'password',
|
||||||
|
reason: e instanceof BackendError ? e.originError.type : 'unknown',
|
||||||
|
});
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,14 +12,17 @@ export interface UserFriendlyErrorResponse {
|
|||||||
stacktrace?: string;
|
stacktrace?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UserFriendlyError implements UserFriendlyErrorResponse {
|
export class UserFriendlyError
|
||||||
status = this.response.status;
|
extends Error
|
||||||
code = this.response.code;
|
implements UserFriendlyErrorResponse
|
||||||
type = this.response.type;
|
{
|
||||||
name = this.response.name;
|
readonly status = this.response.status;
|
||||||
message = this.response.message;
|
readonly code = this.response.code;
|
||||||
args = this.response.args;
|
readonly type = this.response.type;
|
||||||
stacktrace = this.response.stacktrace;
|
override readonly name = this.response.name;
|
||||||
|
override readonly message = this.response.message;
|
||||||
|
readonly args = this.response.args;
|
||||||
|
readonly stacktrace = this.response.stacktrace;
|
||||||
|
|
||||||
static fromAnyError(response: any) {
|
static fromAnyError(response: any) {
|
||||||
if (response instanceof GraphQLError) {
|
if (response instanceof GraphQLError) {
|
||||||
@@ -51,7 +54,9 @@ export class UserFriendlyError implements UserFriendlyErrorResponse {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(private readonly response: UserFriendlyErrorResponse) {}
|
constructor(private readonly response: UserFriendlyErrorResponse) {
|
||||||
|
super(response.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GraphQLError extends BaseGraphQLError {
|
export class GraphQLError extends BaseGraphQLError {
|
||||||
|
|||||||
@@ -382,7 +382,7 @@ export type EventArgs = {
|
|||||||
createWorkspace: { flavour: string };
|
createWorkspace: { flavour: string };
|
||||||
signIn: AuthArgs;
|
signIn: AuthArgs;
|
||||||
signedIn: AuthArgs;
|
signedIn: AuthArgs;
|
||||||
signInFail: AuthArgs;
|
signInFail: AuthArgs & { reason: string };
|
||||||
viewPlans: PaymentEventArgs;
|
viewPlans: PaymentEventArgs;
|
||||||
checkout: PaymentEventArgs;
|
checkout: PaymentEventArgs;
|
||||||
subscribe: PaymentEventArgs;
|
subscribe: PaymentEventArgs;
|
||||||
|
|||||||
Reference in New Issue
Block a user