Skip to content

a promise is not a contract, but it's very nice - #2097

Merged
iAmWillShepherd merged 7 commits into
masterfrom
trap-404-errors
Jun 23, 2017
Merged

iAmWillShepherd merged 7 commits into
masterfrom
trap-404-errors

Conversation

@shiftkey

Copy link
Copy Markdown
Member

As part of the refactoring in #2080 a subtle bug was introduced around how promises raise errors.

If you're working with async/await, you need to await the promise and return the result, rather than returning the promise directly. This is important if you have a try-catch block, as returning the promise means that it escapes this local error handling.

There might be other things to do here (we're tracking #2061 for example) but this should close out #1624 again.

@shiftkey shiftkey mentioned this pull request Jun 23, 2017
@shiftkey shiftkey added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Jun 23, 2017
@iAmWillShepherd iAmWillShepherd self-assigned this Jun 23, 2017
Comment thread app/src/lib/api.ts Outdated
try {
const response = await this.request('GET', `repos/${owner}/${name}`)
return parsedResponse<IAPIRepository>(response)
if (response.status === 404) {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@shiftkey

Copy link
Copy Markdown
Member Author

I took this a bit further to handle the other places where a wiki hits the API and fails. I'm leaving the warning messages because this doesn't properly address #2061 - this just avoids a try-catch invocation...

🍎

Comment thread app/src/lib/api.ts
return parsedResponse<IAPICommit>(response)
} catch (e) {
log.warn(`fetchCommit: not found '${owner}/${name}@${sha}'`, e)
log.warn(`fetchCommit: returned an error '${owner}/${name}@${sha}'`, e)

This comment was marked as spam.

This comment was marked as spam.

@iAmWillShepherd
iAmWillShepherd merged commit 94309dc into master Jun 23, 2017
@iAmWillShepherd
iAmWillShepherd deleted the trap-404-errors branch June 23, 2017 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants