chore(snjs): add error logs when not able to create session (#2240)
This commit is contained in:
@@ -44,7 +44,7 @@ import {
|
|||||||
HttpSuccessResponse,
|
HttpSuccessResponse,
|
||||||
} from '@standardnotes/responses'
|
} from '@standardnotes/responses'
|
||||||
import { CopyPayloadWithContentOverride } from '@standardnotes/models'
|
import { CopyPayloadWithContentOverride } from '@standardnotes/models'
|
||||||
import { LegacySession, MapperInterface, Session, SessionToken } from '@standardnotes/domain-core'
|
import { LegacySession, MapperInterface, Result, Session, SessionToken } from '@standardnotes/domain-core'
|
||||||
import { KeyParamsFromApiResponse, SNRootKeyParams, SNRootKey, CreateNewRootKey } from '@standardnotes/encryption'
|
import { KeyParamsFromApiResponse, SNRootKeyParams, SNRootKey, CreateNewRootKey } from '@standardnotes/encryption'
|
||||||
import { Subscription } from '@standardnotes/security'
|
import { Subscription } from '@standardnotes/security'
|
||||||
import * as Common from '@standardnotes/common'
|
import * as Common from '@standardnotes/common'
|
||||||
@@ -682,17 +682,20 @@ export class SNSessionManager
|
|||||||
|
|
||||||
const user = sharePayload.user
|
const user = sharePayload.user
|
||||||
|
|
||||||
const session = this.createSession(
|
const sessionOrError = this.createSession(
|
||||||
sharePayload.accessToken,
|
sharePayload.accessToken,
|
||||||
sharePayload.accessExpiration,
|
sharePayload.accessExpiration,
|
||||||
sharePayload.refreshToken,
|
sharePayload.refreshToken,
|
||||||
sharePayload.refreshExpiration,
|
sharePayload.refreshExpiration,
|
||||||
sharePayload.readonlyAccess,
|
sharePayload.readonlyAccess,
|
||||||
)
|
)
|
||||||
|
if (sessionOrError.isFailed()) {
|
||||||
|
console.error(sessionOrError.getError())
|
||||||
|
|
||||||
if (session !== null) {
|
return
|
||||||
await this.populateSession(rootKey, user, session, sharePayload.host)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.populateSession(rootKey, user, sessionOrError.getValue(), sharePayload.host)
|
||||||
}
|
}
|
||||||
|
|
||||||
private async populateSession(
|
private async populateSession(
|
||||||
@@ -724,17 +727,26 @@ export class SNSessionManager
|
|||||||
rootKey: SNRootKey
|
rootKey: SNRootKey
|
||||||
wrappingKey?: SNRootKey
|
wrappingKey?: SNRootKey
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
const session = this.createSession(
|
const sessionOrError = this.createSession(
|
||||||
dto.session.access_token,
|
dto.session.access_token,
|
||||||
dto.session.access_expiration,
|
dto.session.access_expiration,
|
||||||
dto.session.refresh_token,
|
dto.session.refresh_token,
|
||||||
dto.session.refresh_expiration,
|
dto.session.refresh_expiration,
|
||||||
dto.session.readonly_access,
|
dto.session.readonly_access,
|
||||||
)
|
)
|
||||||
|
if (sessionOrError.isFailed()) {
|
||||||
|
console.error(sessionOrError.getError())
|
||||||
|
|
||||||
if (session !== null) {
|
return
|
||||||
await this.populateSession(dto.rootKey, dto.user, session, this.apiService.getHost(), dto.wrappingKey)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.populateSession(
|
||||||
|
dto.rootKey,
|
||||||
|
dto.user,
|
||||||
|
sessionOrError.getValue(),
|
||||||
|
this.apiService.getHost(),
|
||||||
|
dto.wrappingKey,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -755,16 +767,25 @@ export class SNSessionManager
|
|||||||
await this.populateSession(rootKey, user, sessionOrError.getValue(), this.apiService.getHost(), wrappingKey)
|
await this.populateSession(rootKey, user, sessionOrError.getValue(), this.apiService.getHost(), wrappingKey)
|
||||||
}
|
}
|
||||||
} else if (data.session) {
|
} else if (data.session) {
|
||||||
const session = this.createSession(
|
const sessionOrError = this.createSession(
|
||||||
data.session.access_token,
|
data.session.access_token,
|
||||||
data.session.access_expiration,
|
data.session.access_expiration,
|
||||||
data.session.refresh_token,
|
data.session.refresh_token,
|
||||||
data.session.refresh_expiration,
|
data.session.refresh_expiration,
|
||||||
data.session.readonly_access,
|
data.session.readonly_access,
|
||||||
)
|
)
|
||||||
if (session !== null && user) {
|
if (sessionOrError.isFailed()) {
|
||||||
await this.populateSession(rootKey, user, session, this.apiService.getHost(), wrappingKey)
|
console.error(sessionOrError.getError())
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
if (!user) {
|
||||||
|
console.error('No user in response')
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.populateSession(rootKey, user, sessionOrError.getValue(), this.apiService.getHost(), wrappingKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -774,25 +795,25 @@ export class SNSessionManager
|
|||||||
refreshTokenValue: string,
|
refreshTokenValue: string,
|
||||||
refreshExpiration: number,
|
refreshExpiration: number,
|
||||||
readonlyAccess: boolean,
|
readonlyAccess: boolean,
|
||||||
): Session | null {
|
): Result<Session> {
|
||||||
const accessTokenOrError = SessionToken.create(accessTokenValue, accessExpiration)
|
const accessTokenOrError = SessionToken.create(accessTokenValue, accessExpiration)
|
||||||
if (accessTokenOrError.isFailed()) {
|
if (accessTokenOrError.isFailed()) {
|
||||||
return null
|
return Result.fail(`Could not create session: ${accessTokenOrError.getError()}`)
|
||||||
}
|
}
|
||||||
const accessToken = accessTokenOrError.getValue()
|
const accessToken = accessTokenOrError.getValue()
|
||||||
|
|
||||||
const refreshTokenOrError = SessionToken.create(refreshTokenValue, refreshExpiration)
|
const refreshTokenOrError = SessionToken.create(refreshTokenValue, refreshExpiration)
|
||||||
if (refreshTokenOrError.isFailed()) {
|
if (refreshTokenOrError.isFailed()) {
|
||||||
return null
|
return Result.fail(`Could not create session: ${refreshTokenOrError.getError()}`)
|
||||||
}
|
}
|
||||||
const refreshToken = refreshTokenOrError.getValue()
|
const refreshToken = refreshTokenOrError.getValue()
|
||||||
|
|
||||||
const sessionOrError = Session.create(accessToken, refreshToken, readonlyAccess)
|
const sessionOrError = Session.create(accessToken, refreshToken, readonlyAccess)
|
||||||
if (sessionOrError.isFailed()) {
|
if (sessionOrError.isFailed()) {
|
||||||
return null
|
return Result.fail(`Could not create session: ${sessionOrError.getError()}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return sessionOrError.getValue()
|
return Result.ok(sessionOrError.getValue())
|
||||||
}
|
}
|
||||||
|
|
||||||
override getDiagnostics(): Promise<DiagnosticInfo | undefined> {
|
override getDiagnostics(): Promise<DiagnosticInfo | undefined> {
|
||||||
|
|||||||
Reference in New Issue
Block a user