Skip to content

Commit

Permalink
Log HTTP 409 error responses with breadcrumbs
Browse files Browse the repository at this point in the history
The breadcrumbs were left in places leading up to `/v2/login/create` and
`/v2/login/keys` endpoints to the login server.
  • Loading branch information
samholmes committed Sep 2, 2024
1 parent 39578f7 commit 8a70300
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- added: Log HTTP 409 errors from login server with breadcrumbs.

## 2.13.1 (2024-08-23)

- fixed: Use full URI to determine whether a request has previously succeeded CORS
Expand Down
12 changes: 12 additions & 0 deletions src/core/account/account-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ export function makeAccountApi(ai: ApiInput, accountId: string): EdgeAccount {
// ----------------------------------------------------------------

async fetchLobby(lobbyId: string): Promise<EdgeLobby> {
// For crash errors:
ai.props.log.breadcrumb('EdgeAccount.fetchLobby', {})

lockdown()
return await makeLobbyApi(ai, accountId, lobbyId)
},
Expand Down Expand Up @@ -380,6 +383,9 @@ export function makeAccountApi(ai: ApiInput, accountId: string): EdgeAccount {
},

async createWallet(walletType: string, keys?: object): Promise<string> {
// For crash errors:
ai.props.log.breadcrumb('EdgeAccount.createWallet', {})

const { login, loginTree } = accountState()

const walletInfo = await makeCurrencyWalletKeys(ai, walletType, { keys })
Expand Down Expand Up @@ -493,6 +499,9 @@ export function makeAccountApi(ai: ApiInput, accountId: string): EdgeAccount {
walletType: string,
opts: EdgeCreateCurrencyWalletOptions = {}
): Promise<EdgeCurrencyWallet> {
// For crash errors:
ai.props.log.breadcrumb('EdgeAccount.createCurrencyWallet', {})

const { login, loginTree } = accountState()

const walletInfo = await makeCurrencyWalletKeys(ai, walletType, opts)
Expand All @@ -515,6 +524,9 @@ export function makeAccountApi(ai: ApiInput, accountId: string): EdgeAccount {
async createCurrencyWallets(
createWallets: EdgeCreateCurrencyWallet[]
): Promise<Array<EdgeResult<EdgeCurrencyWallet>>> {
// For crash errors:
ai.props.log.breadcrumb('EdgeAccount.makeMemoryWallet', {})

const { login, loginTree } = accountState()

// Create the keys:
Expand Down
10 changes: 10 additions & 0 deletions src/core/account/account-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,23 @@ export async function ensureAccountExists(
loginTree: LoginTree,
appId: string
): Promise<LoginTree> {
// For crash errors:
ai.props.log.breadcrumb('ensureAccountExists', {})

const accountType = makeAccountType(appId)

// If there is no app login, make that:
const login = searchTree(loginTree, login => login.appId === appId)
if (login == null) {
// For crash errors:
ai.props.log.breadcrumb('createChildLogin', {})
return await createChildLogin(ai, loginTree, loginTree, appId)
}

// Otherwise, make the repo:
if (findFirstKey(login.keyInfos, accountType) == null) {
// For crash errors:
ai.props.log.breadcrumb('createAccountRepo', {})
checkLogin(login)
const keyInfo = makeKeyInfo(
accountType,
Expand All @@ -101,6 +108,9 @@ export async function makeAccount(
loginType: LoginType,
opts: EdgeAccountOptions
): Promise<EdgeAccount> {
// For crash errors:
ai.props.log.breadcrumb('makeAccount', {})

const { pauseWallets = false } = opts
const { log } = ai.props
log.warn(
Expand Down
6 changes: 6 additions & 0 deletions src/core/account/lobby-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ async function approveLoginRequest(
lobbyId: string,
lobbyJson: EdgeLobbyRequest
): Promise<void> {
// For crash errors:
ai.props.log.breadcrumb('approveLoginRequest', {})

const { login, loginTree } = ai.props.state.accounts[accountId]

// Ensure that the login object & account repo exist:
Expand Down Expand Up @@ -153,6 +156,9 @@ async function unpackLoginRequest(
lobbyJson: EdgeLobbyRequest,
appId: string
): Promise<EdgeLoginRequest> {
// For crash errors:
ai.props.log.breadcrumb('unpackLoginRequest', {})

const info = await fetchAppIdInfo(ai, appId)

// Make the API:
Expand Down
15 changes: 15 additions & 0 deletions src/core/context/context-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ export function makeContextApi(ai: ApiInput): EdgeContext {
async createAccount(
opts: EdgeCreateAccountOptions & EdgeAccountOptions
): Promise<EdgeAccount> {
// For crash errors:
ai.props.log.breadcrumb('EdgeContext.createAccount', {})

if (opts.username != null) {
opts.username = fixUsername(opts.username)
}
Expand Down Expand Up @@ -116,6 +119,9 @@ export function makeContextApi(ai: ApiInput): EdgeContext {
password: string,
opts: EdgeAccountOptions = {}
): Promise<EdgeAccount> {
// For crash errors:
ai.props.log.breadcrumb('EdgeContext.loginWithPassword', {})

username = fixUsername(username)
const stashTree = getStashByUsername(ai, username)
const loginTree = await loginPassword(
Expand All @@ -134,6 +140,9 @@ export function makeContextApi(ai: ApiInput): EdgeContext {
pin: string,
opts = {}
): Promise<EdgeAccount> {
// For crash errors:
ai.props.log.breadcrumb('EdgeContext.loginWithPIN', {})

const { useLoginId = false } = opts

const stashTree = useLoginId
Expand All @@ -153,6 +162,9 @@ export function makeContextApi(ai: ApiInput): EdgeContext {
answers: string[],
opts: EdgeAccountOptions = {}
): Promise<EdgeAccount> {
// For crash errors:
ai.props.log.breadcrumb('EdgeContext.loginWithRecovery2', {})

username = fixUsername(username)
const stashTree = getStashByUsername(ai, username)
const loginTree = await loginRecovery2(
Expand All @@ -176,6 +188,9 @@ export function makeContextApi(ai: ApiInput): EdgeContext {
async requestEdgeLogin(
opts?: EdgeAccountOptions
): Promise<EdgePendingEdgeLogin> {
// For crash errors:
ai.props.log.breadcrumb('EdgeContext.requestEdgeLogin', {})

return await requestEdgeLogin(ai, appId, opts)
},

Expand Down
6 changes: 6 additions & 0 deletions src/core/login/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export async function makeCreateKit(
appId: string,
opts: LoginCreateOpts
): Promise<LoginKit> {
// For crash errors:
ai.props.log.breadcrumb('makeCreateKit', {})

const { keyInfo, password, pin, username } = opts
const { io } = ai.props

Expand Down Expand Up @@ -144,6 +147,9 @@ export async function createLogin(
accountOpts: EdgeAccountOptions,
opts: LoginCreateOpts
): Promise<LoginTree> {
// For crash errors:
ai.props.log.breadcrumb('createLogin', {})

const { now = new Date() } = accountOpts

const kit = await makeCreateKit(ai, undefined, '', opts)
Expand Down
3 changes: 3 additions & 0 deletions src/core/login/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ async function unpackAccount(
appId: string,
opts: EdgeAccountOptions
): Promise<EdgeAccount> {
// For crash errors:
ai.props.log.breadcrumb('unpackAccount', {})

const { now = new Date() } = opts
const { loginKey, loginStash: stashTree } = payload

Expand Down
3 changes: 3 additions & 0 deletions src/core/login/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export function makeKeysKit(
login: LoginTree,
keyInfos: EdgeWalletInfo[]
): LoginKit {
// For crash errors:
ai.props.log.breadcrumb('makeKeysKit', {})

const { io } = ai.props
const keyBoxes = keyInfos.map(info =>
encrypt(
Expand Down
7 changes: 7 additions & 0 deletions src/core/login/login-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ export function loginFetch(
response => {
const time = Date.now() - start
log(`${method} ${fullUri} returned ${response.status} in ${time}ms`)

if (response.status === 409) {
log.crash(`Login API conflict error`, {
path
})
}

return response.json().then(parseReply, () => {
throw new Error(`Invalid reply JSON, HTTP status ${response.status}`)
})
Expand Down

0 comments on commit 8a70300

Please sign in to comment.