Skip to content

Commit

Permalink
fix: fixed error handling in github-manager.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
prisis committed May 14, 2020
1 parent c21742a commit 6972d59
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ trim_trailing_whitespace = true
[*.yml]
indent_size = 2

[*.ts]
indent_size = 2

[package.json]
indent_size = 2
16 changes: 9 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5053,10 +5053,11 @@ class GithubManager {
return true;
}
catch (error) {
if (error.name === 'HttpError' && error.status === 404) {
const err = error;
if (err.name === 'HttpError' && err.status === 404) {
return false;
}
throw new Error(`Failed to check if branch ${branch} exist; ${util_1.inspect(error)}`);
throw new Error(`Failed to check if branch ${branch} exist; ${util_1.inspect(err)}`);
}
})
};
Expand All @@ -5075,11 +5076,12 @@ class GithubManager {
});
}
catch (error) {
core.debug(util_1.inspect(error));
if (!!error.errors &&
(error.errors[0].message.include('No commits between') ||
error.errors[0].message.include('A pull request already exists for'))) {
core.info(error.errors[0].message);
const err = error;
core.debug(util_1.inspect(err));
if (err.name === 'HttpError' &&
(err.message.includes('No commits between') ||
err.message.includes('A pull request already exists for'))) {
core.info(err.message);
process.exit(0); // there is currently no neutral exit code
}
else {
Expand Down
23 changes: 13 additions & 10 deletions src/github-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
IGithubManager,
IGithubManagerBranch,
IGithubManagerPulls,
IGithubManagerRepos
IGithubManagerRepos,
OctokitHttpError
} from './interfaces'

const IS_WINDOWS = process.platform === 'win32'
Expand Down Expand Up @@ -82,12 +83,14 @@ export class GithubManager implements IGithubManager {

return true
} catch (error) {
if (error.name === 'HttpError' && error.status === 404) {
const err: OctokitHttpError = error

if (err.name === 'HttpError' && err.status === 404) {
return false
}

throw new Error(
`Failed to check if branch ${branch} exist; ${inspect(error)}`
`Failed to check if branch ${branch} exist; ${inspect(err)}`
)
}
}
Expand All @@ -114,16 +117,16 @@ export class GithubManager implements IGithubManager {
body
})
} catch (error) {
core.debug(inspect(error))
const err: OctokitHttpError = error

core.debug(inspect(err))

if (
!!error.errors &&
(error.errors[0].message.include('No commits between') ||
error.errors[0].message.include(
'A pull request already exists for'
))
err.name === 'HttpError' &&
(err.message.includes('No commits between') ||
err.message.includes('A pull request already exists for'))
) {
core.info(error.errors[0].message)
core.info(err.message)

process.exit(0) // there is currently no neutral exit code
} else {
Expand Down
23 changes: 23 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {URL} from 'url'
import {RequestOptions, ResponseHeaders} from '@octokit/types'

export interface IPayloadRepository {
full_name?: string
Expand Down Expand Up @@ -211,3 +212,25 @@ export interface ISettings {

clean: boolean
}

export interface OctokitHttpError extends Error {
name: string
/**
* http status code
*/
status: number
/**
* http status code
*
* @deprecated `error.code` is deprecated in favor of `error.status`
*/
code: number
/**
* error response headers
*/
headers: ResponseHeaders
/**
* Request options that lead to the error.
*/
request: RequestOptions
}

0 comments on commit 6972d59

Please sign in to comment.