Skip to content

Commit

Permalink
feat: add more context to error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Oct 29, 2018
1 parent 1d14595 commit 4388cd3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
28 changes: 12 additions & 16 deletions lib/handle-pull-request-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const overwriteLegacyCommitStatus = require('./legacy/overwrite-commit-status')

async function handlePullRequestChange (app, context) {
const { action, pull_request: pr, repository: repo } = context.payload
let log = context.log

try {
// 1. get new status based on marketplace plan
Expand All @@ -32,7 +33,7 @@ async function handlePullRequestChange (app, context) {
// indefinitely, hence the override. See https://github.com/wip/app/issues/89#notes-on-update-to-marketplace-version
const didLegacyOveride = await overwriteLegacyCommitStatus(context)

const log = getLogChild({ context, action, plan, newStatus, repo, hasChange, shortUrl, didLegacyOveride })
log = getLogChild({ context, action, plan, newStatus, repo, hasChange, shortUrl, didLegacyOveride })

// if status did not change then don’t call .createStatus. Quotas for mutations
// are much more restrictive so we want to avoid them if possible
Expand All @@ -41,11 +42,8 @@ async function handlePullRequestChange (app, context) {
}

// 3. Create check run
if (plan === 'free') {
await setStatusFree(newStatus, context)
} else {
await setStatusPro(newStatus, context)
}
const setStatus = plan === 'free' ? setStatusFree : setStatusPro
await setStatus(newStatus, context)

log.stateChanged()
} catch (error) {
Expand All @@ -55,17 +53,15 @@ async function handlePullRequestChange (app, context) {
for (const key in parsed) {
error[key] = parsed[key]
}
} catch (e) {}

// Erro code 403 (Resource not accessible by integration) means that
// the user did not yet accept the new permissions, so we handle it the
// old school way
if (error.code === 403) {
return legacyHandler(context)
}

context.log.error(error)
} catch (e) {
context.log.error(error)
// Erro code 403 (Resource not accessible by integration) means that
// the user did not yet accept the new permissions, so we handle it the
// old school way
if (error.code === 403) {
return legacyHandler(context)
}

log.error(error)
}
}
7 changes: 3 additions & 4 deletions lib/legacy/handle-pull-request-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ async function handlePullRequestChange (context) {
for (const key in parsed) {
error[key] = parsed[key]
}
context.log.error(error)
} catch (e) {
context.log.error(error)
}
} catch (e) {}

log.error(error)
}
}

Expand Down
3 changes: 3 additions & 0 deletions lib/logs/get-child.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ function getChildLog ({ context, action, plan, newStatus, repo, hasChange, short
message += ` - "${newStatus.match}" found in ${newStatus.location}`
}
log.info(message)
},
error (error) {
log.error(error)
}
}
}

1 comment on commit 4388cd3

@vercel
Copy link

@vercel vercel bot commented on 4388cd3 Oct 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully aliased the URL https://wip-ajczxlhgkf.now.sh to the following alias.

Please sign in to comment.