Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve error logs #37

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/jira-connector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import axios, { AxiosInstance } from 'axios';
import { isAxiosError } from './utils';
import { getInputs } from './action-inputs';
import { JIRA, JIRADetails } from './types';
import { error as coreError, info as coreInfo } from '@actions/core';

export class JiraConnector {
client: AxiosInstance;
Expand Down Expand Up @@ -46,8 +48,9 @@ export class JiraConnector {
},
};
} catch (error) {
if (error.response) {
throw new Error(JSON.stringify(error.response, null, 4));
if (isAxiosError(error) && error?.response?.status === 401) {
Copy link
Owner

Choose a reason for hiding this comment

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

I also played with this and could not get a 401, even if I'm having incorrect credentials, I'm getting 404

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's weird, I am not sure how that used to play out for me though...
Maybe a simple info-log with the error code could do the trick, whatever the type of error

coreError('Jira request failed, check your jira-token.');
coreInfo('Does your jira-token include the required prefix ? See https://github.com/cakeinpanic/jira-description-action#jira-token');
Copy link
Owner

Choose a reason for hiding this comment

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

love this!

}
throw error;
}
Expand Down
1 change: 0 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ async function run(): Promise<void> {
const details = await jiraConnector.getTicketDetails(issueKey);
await githubConnector.updatePrDetails(details);
} catch (error) {
console.log('JIRA key was not found');
Copy link
Owner

Choose a reason for hiding this comment

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

please don't remove this output, it's needed for the case when token is ok, just the jira task not exisitng

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I see, my mistake

core.error(error.message);

if (FAIL_WHEN_JIRA_ISSUE_NOT_FOUND) {
Expand Down
3 changes: 3 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
WARNING_MESSAGE_ABOUT_HIDDEN_MARKERS,
} from './constants';
import { JIRADetails } from './types';
import { AxiosError } from 'axios';

const getJIRAIssueKey = (input: string, regexp: RegExp = JIRA_REGEX_MATCHER): string | null => {
const matches = regexp.exec(input);
Expand Down Expand Up @@ -78,3 +79,5 @@ export const buildPRDescription = (details: JIRADetails) => {

`;
};

export const isAxiosError = <T = any>(err: Error): err is AxiosError<T> => !!(err as AxiosError)?.isAxiosError;