Skip to content

Commit 6972d59

Browse files
committed
fix: fixed error handling in github-manager.ts
1 parent c21742a commit 6972d59

File tree

4 files changed

+48
-17
lines changed

4 files changed

+48
-17
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ trim_trailing_whitespace = true
1111
[*.yml]
1212
indent_size = 2
1313

14+
[*.ts]
15+
indent_size = 2
16+
1417
[package.json]
1518
indent_size = 2

dist/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5053,10 +5053,11 @@ class GithubManager {
50535053
return true;
50545054
}
50555055
catch (error) {
5056-
if (error.name === 'HttpError' && error.status === 404) {
5056+
const err = error;
5057+
if (err.name === 'HttpError' && err.status === 404) {
50575058
return false;
50585059
}
5059-
throw new Error(`Failed to check if branch ${branch} exist; ${util_1.inspect(error)}`);
5060+
throw new Error(`Failed to check if branch ${branch} exist; ${util_1.inspect(err)}`);
50605061
}
50615062
})
50625063
};
@@ -5075,11 +5076,12 @@ class GithubManager {
50755076
});
50765077
}
50775078
catch (error) {
5078-
core.debug(util_1.inspect(error));
5079-
if (!!error.errors &&
5080-
(error.errors[0].message.include('No commits between') ||
5081-
error.errors[0].message.include('A pull request already exists for'))) {
5082-
core.info(error.errors[0].message);
5079+
const err = error;
5080+
core.debug(util_1.inspect(err));
5081+
if (err.name === 'HttpError' &&
5082+
(err.message.includes('No commits between') ||
5083+
err.message.includes('A pull request already exists for'))) {
5084+
core.info(err.message);
50835085
process.exit(0); // there is currently no neutral exit code
50845086
}
50855087
else {

src/github-manager.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
IGithubManager,
1212
IGithubManagerBranch,
1313
IGithubManagerPulls,
14-
IGithubManagerRepos
14+
IGithubManagerRepos,
15+
OctokitHttpError
1516
} from './interfaces'
1617

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

8384
return true
8485
} catch (error) {
85-
if (error.name === 'HttpError' && error.status === 404) {
86+
const err: OctokitHttpError = error
87+
88+
if (err.name === 'HttpError' && err.status === 404) {
8689
return false
8790
}
8891

8992
throw new Error(
90-
`Failed to check if branch ${branch} exist; ${inspect(error)}`
93+
`Failed to check if branch ${branch} exist; ${inspect(err)}`
9194
)
9295
}
9396
}
@@ -114,16 +117,16 @@ export class GithubManager implements IGithubManager {
114117
body
115118
})
116119
} catch (error) {
117-
core.debug(inspect(error))
120+
const err: OctokitHttpError = error
121+
122+
core.debug(inspect(err))
118123

119124
if (
120-
!!error.errors &&
121-
(error.errors[0].message.include('No commits between') ||
122-
error.errors[0].message.include(
123-
'A pull request already exists for'
124-
))
125+
err.name === 'HttpError' &&
126+
(err.message.includes('No commits between') ||
127+
err.message.includes('A pull request already exists for'))
125128
) {
126-
core.info(error.errors[0].message)
129+
core.info(err.message)
127130

128131
process.exit(0) // there is currently no neutral exit code
129132
} else {

src/interfaces.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {URL} from 'url'
2+
import {RequestOptions, ResponseHeaders} from '@octokit/types'
23

34
export interface IPayloadRepository {
45
full_name?: string
@@ -211,3 +212,25 @@ export interface ISettings {
211212

212213
clean: boolean
213214
}
215+
216+
export interface OctokitHttpError extends Error {
217+
name: string
218+
/**
219+
* http status code
220+
*/
221+
status: number
222+
/**
223+
* http status code
224+
*
225+
* @deprecated `error.code` is deprecated in favor of `error.status`
226+
*/
227+
code: number
228+
/**
229+
* error response headers
230+
*/
231+
headers: ResponseHeaders
232+
/**
233+
* Request options that lead to the error.
234+
*/
235+
request: RequestOptions
236+
}

0 commit comments

Comments
 (0)