mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-21 20:16:26 +08:00
@@ -1,3 +1,5 @@
|
||||
import type { UserFriendlyError } from '@affine/graphql';
|
||||
|
||||
export class NetworkError extends Error {
|
||||
constructor(
|
||||
public readonly originError: Error,
|
||||
@@ -14,7 +16,7 @@ export function isNetworkError(error: Error): error is NetworkError {
|
||||
|
||||
export class BackendError extends Error {
|
||||
constructor(
|
||||
public readonly originError: Error,
|
||||
public readonly originError: UserFriendlyError,
|
||||
public readonly status?: number
|
||||
) {
|
||||
super(`Server error: ${originError.message}`);
|
||||
|
||||
@@ -12,6 +12,7 @@ import { distinctUntilChanged, map, skip } from 'rxjs';
|
||||
|
||||
import type { UrlService } from '../../url';
|
||||
import { type AuthAccountInfo, AuthSession } from '../entities/session';
|
||||
import { BackendError } from '../error';
|
||||
import type { AuthStore } from '../stores/auth';
|
||||
import type { FetchService } from './fetch';
|
||||
|
||||
@@ -111,7 +112,10 @@ export class AuthService extends Service {
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
track.$.$.auth.signInFail({ method: 'magic-link' });
|
||||
track.$.$.auth.signInFail({
|
||||
method: 'magic-link',
|
||||
reason: e instanceof BackendError ? e.originError.type : 'unknown',
|
||||
});
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -129,7 +133,10 @@ export class AuthService extends Service {
|
||||
this.session.revalidate();
|
||||
track.$.$.auth.signedIn({ method: 'magic-link' });
|
||||
} catch (e) {
|
||||
track.$.$.auth.signInFail({ method: 'magic-link' });
|
||||
track.$.$.auth.signInFail({
|
||||
method: 'magic-link',
|
||||
reason: e instanceof BackendError ? e.originError.type : 'unknown',
|
||||
});
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -166,7 +173,11 @@ export class AuthService extends Service {
|
||||
|
||||
return url;
|
||||
} catch (e) {
|
||||
track.$.$.auth.signInFail({ method: 'oauth', provider });
|
||||
track.$.$.auth.signInFail({
|
||||
method: 'oauth',
|
||||
provider,
|
||||
reason: e instanceof BackendError ? e.originError.type : 'unknown',
|
||||
});
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -186,7 +197,11 @@ export class AuthService extends Service {
|
||||
track.$.$.auth.signedIn({ method: 'oauth', provider });
|
||||
return res.json();
|
||||
} catch (e) {
|
||||
track.$.$.auth.signInFail({ method: 'oauth', provider });
|
||||
track.$.$.auth.signInFail({
|
||||
method: 'oauth',
|
||||
provider,
|
||||
reason: e instanceof BackendError ? e.originError.type : 'unknown',
|
||||
});
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -212,7 +227,10 @@ export class AuthService extends Service {
|
||||
this.session.revalidate();
|
||||
track.$.$.auth.signedIn({ method: 'password' });
|
||||
} catch (e) {
|
||||
track.$.$.auth.signInFail({ method: 'password' });
|
||||
track.$.$.auth.signInFail({
|
||||
method: 'password',
|
||||
reason: e instanceof BackendError ? e.originError.type : 'unknown',
|
||||
});
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user