Skip to content

Commit

Permalink
newErrorHandling removed
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRefactoring committed Oct 13, 2023
1 parent 3317f97 commit 9cc1695
Show file tree
Hide file tree
Showing 43 changed files with 42 additions and 110 deletions.
55 changes: 0 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Usability, consistency, and performance are key focuses of jira.js, and it also

- [Installation](#installation)
- [Documentation](#documentation)
- [Deprecation warnings](#deprecation-warnings)
- [Usage](#usage)
- [Authentication](#authentication)
- [Basic](#basic-authentication)
Expand Down Expand Up @@ -50,56 +49,6 @@ yarn add jira.js

You can find the documentation [here](https://mrrefactoring.github.io/jira.js/).

## Deprecation warnings

1. Deprecation warning: New error handling mechanism added. Please use `newErrorHandling: true` in config
> We are using a new error handling mechanism (instead throwing raw axios error will be showed API response). For enable it, make following changes in your config:
> ```ts
> const client = new Version3Client({
> host: '...',
> newErrorHandling: true, // This flag enable new error handling.
> });
>
> // Examples
>
> /** Old error handling **/
>
> const client = new Version3Client({ host: '...' });
>
> client.issues.createIssue();
>
> // Output:
> // {
> // code: 'ERR_BAD_REQUEST',
> // config: { a lot of stuff here },
> // request: { a lot of stuff here },
> // response: {
> // a lot of stuff here
> // data: {
> // errorMessages: [],
> // errors: { project: 'Specify a valid project ID or key' }
> // },
> // a lot of stuff here
> // },
> // a lot of stuff here
> // }
>
> /** New error handling **/
>
> const client = new Version3Client({ host: '...', newErrorHandling: true });
>
> client.issues.createIssue();
>
> // Output:
> // {
> // code: 'ERR_BAD_REQUEST',
> // status: 400,
> // errorMessages: [],
> // errors: { project: 'Specify a valid project ID or key' }
> // }
> ```
## Usage

#### Authentication
Expand Down Expand Up @@ -194,7 +143,6 @@ const client = new Version3Client({
apiToken,
},
},
newErrorHandling: true,
});

async function main() {
Expand Down Expand Up @@ -273,9 +221,7 @@ Available groups:
- [filterSharing](https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-filter-sharing/#api-group-filter-sharing)
- [groupAndUserPicker](https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-group-and-user-picker/#api-group-group-and-user-picker)
- [groups](https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-groups/#api-group-groups)
- [instanceInformation](https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-instance-information/#api-group-instance-information)
- [issues](https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issues/#api-group-issues)
- [issueAdjustmentsApps](https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issue-adjustments--apps-/#api-group-issue-adjustments--apps-)
- [issueAttachments](https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issue-attachments/#api-group-issue-attachments)
- [issueComments](https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issue-comments/#api-group-issue-comments)
- [issueCustomFieldConfigurationApps](https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issue-custom-field-configuration--apps-/#api-group-issue-custom-field-configuration--apps-)
Expand Down Expand Up @@ -366,7 +312,6 @@ Available groups:
- [groups](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-groups/#api-group-groups)
- [instanceInformation](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-instance-information/#api-group-instance-information)
- [issues](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-group-issues)
- [issueAdjustmentsApps](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-adjustments--apps-/#api-group-issue-adjustments--apps-)
- [issueAttachments](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-group-issue-attachments)
- [issueComments](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-comments/#api-group-issue-comments)
- [issueCustomFieldConfigurationApps](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-custom-field-configuration--apps-/#api-group-issue-custom-field-configuration--apps-)
Expand Down
1 change: 0 additions & 1 deletion examples/src/addFixVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ async function addFixVersion() {
authentication: {
basic: { email, apiToken },
},
newErrorHandling: true,
});

const { id: issueIdOrKey } = await createIssue(client);
Expand Down
1 change: 0 additions & 1 deletion examples/src/addWorklog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ async function addWorklog() {
authentication: {
basic: { email, apiToken },
},
newErrorHandling: true,
});

// Used to reduce the amount of code that is not directly related to creating a worklog
Expand Down
1 change: 0 additions & 1 deletion examples/src/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const client = new Version3Client({
authentication: {
basic: { email, apiToken },
},
newErrorHandling: true,
});

async function main() {
Expand Down
1 change: 0 additions & 1 deletion examples/src/getAllWorklogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ async function getAllWorklogs() {
authentication: {
basic: { email, apiToken }
},
newErrorHandling: true,
});

// Used to reduce the amount of code that is not directly related to getting a worklogs
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jira.js",
"version": "2.20.1",
"version": "3.0.0",
"description": "A comprehensive JavaScript/TypeScript library designed for both Node.JS and browsers, facilitating seamless interaction with the Atlassian Jira API.",
"main": "out/index.js",
"types": "out/index.d.ts",
Expand Down
5 changes: 2 additions & 3 deletions src/clients/baseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ export class BaseClient implements Client {
}

handleFailedResponse<T>(e: Error, callback?: Callback<T> | never): void {
const err =
this.config.newErrorHandling && axios.isAxiosError(e) && e.response ? this.buildNewErrorHandlingResponse(e) : e;
const err = axios.isAxiosError(e) && e.response ? this.buildErrorHandlingResponse(e) : e;

const callbackErrorHandler = callback && ((error: Config.Error) => callback(error));
const defaultErrorHandler = (error: Error) => {
Expand All @@ -133,7 +132,7 @@ export class BaseClient implements Client {
return errorHandler(err);
}

private buildNewErrorHandlingResponse(error: AxiosError<any>) {
private buildErrorHandlingResponse(error: AxiosError<any>) {
return {
code: error.code,
status: error.response?.status,
Expand Down
2 changes: 0 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export interface Config {
baseRequestConfig?: Config.BaseRequestConfig;
authentication?: Config.Authentication;
middlewares?: Config.Middlewares;
/** Enable new API error handling. `false` by default. */
newErrorHandling?: boolean;
}

export namespace Config {
Expand Down
2 changes: 1 addition & 1 deletion src/version2/models/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface Comment {
/** The date and time at which the comment was created. */
created?: string;
/** The ID of the comment. */
id: string;
id?: string;
/**
* Whether the comment was added from an email sent by a person who is not part of the issue. See [Allow external
* emails to be added as comments on
Expand Down
2 changes: 1 addition & 1 deletion src/version3/models/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface Comment {
/** The URL of the comment. */
self?: string;
/** The ID of the comment. */
id: string;
id?: string;
author?: UserDetails;
/**
* The comment text in [Atlassian Document
Expand Down
1 change: 0 additions & 1 deletion tests/integration/utils/getClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ClientType, Config, createClient } from '../../../src';

const config = {
host: process.env.HOST!,
newErrorHandling: true,
authentication: {
basic: {
email: process.env.EMAIL!,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/agile/board.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as sinon from 'sinon';
import { AgileClient } from '../../../src';
import test from 'ava';

const config = { host: 'http://localhost', newErrorHandling: true };
const config = { host: 'http://localhost' };

test('getBoard should accept following parameters', t => {
const client = new AgileClient(config);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/agile/issue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AgileClient } from '../../../src';
import test from 'ava';

test('getIssue should accept follow parameters', t => {
const client = new AgileClient({ host: 'http://localhost', newErrorHandling: true });
const client = new AgileClient({ host: 'http://localhost' });
const sendRequestStub = sinon.stub(client, 'sendRequest');

client.issue.getIssue({ issueIdOrKey: 'key' });
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/agile/sprint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AgileClient } from '../../../src';
import test from 'ava';

test('moveIssuesToSprintAndRank should accept follow parameters', t => {
const client = new AgileClient({ host: 'http://localhost', newErrorHandling: true });
const client = new AgileClient({ host: 'http://localhost' });
const sendRequestStub = sinon.stub(client, 'sendRequest');

client.sprint.moveIssuesToSprintAndRank({
Expand Down
3 changes: 0 additions & 3 deletions tests/unit/clients/baseClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ test('should create X-Atlassian-Token: no-check header in requests', t => {
const client = new BaseClient({
host: 'http://localhost',
noCheckAtlassianToken: true,
newErrorHandling: true,
});

// @ts-ignore
Expand All @@ -32,7 +31,6 @@ test('should not create X-Atlassian-Token: no-check header in requests case 1',
const client = new BaseClient({
host: 'http://localhost',
noCheckAtlassianToken: false,
newErrorHandling: true,
});

// @ts-ignore
Expand All @@ -55,7 +53,6 @@ test('should not create X-Atlassian-Token: no-check header in requests case 1',
test('should create X-Atlassian-Token: no-check header in requests case 2', t => {
const client = new BaseClient({
host: 'http://localhost',
newErrorHandling: true,
});

// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/createClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from 'ava';
import { AgileClient, BaseClient, ClientType, createClient, Version2Client, Version3Client } from '../../src';

const defaultConfig = { host: 'http://localhost', newErrorHandling: true };
const defaultConfig = { host: 'http://localhost' };

test('should create Agile client', t => {
const client = createClient(ClientType.Agile, defaultConfig);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/version2/appMigration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const entity = {
value: 'v',
};

const config = { host: 'http://localhost', newErrorHandling: true };
const config = { host: 'http://localhost' };

test('updateEntityPropertiesValue should accept actual parameters', t => {
const client = new Version2Client(config);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/version2/issueComments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as sinon from 'sinon';
import test from 'ava';
import { IssueComments, Version2Client } from '../../../src/version2';

const client = new Version2Client({ host: 'http://localhost', newErrorHandling: true });
const client = new Version2Client({ host: 'http://localhost' });
const sendRequestStub = sinon.stub(client, 'sendRequest');
const issueComments = new IssueComments(client);

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/version2/issueFields.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import test from 'ava';
import { Version2Client } from '../../../src';

test('getFields should calls without parameters', t => {
const client = new Version2Client({ host: 'http://localhost', newErrorHandling: true });
const client = new Version2Client({ host: 'http://localhost' });
const sendRequestStub = sinon.stub(client, 'sendRequest');

client.issueFields.getFields();
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/version2/issueLinks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import * as sinon from 'sinon';
import test from 'ava';
import { IssueLinks, Version2Client } from '../../../src/version2';

const client = new Version2Client({ host: 'http://localhost', newErrorHandling: true });
const client = new Version2Client({ host: 'http://localhost' });
const sendRequestStub = sinon.stub(client, 'sendRequest');
let issueLinks = new IssueLinks(client);

test('linkIssues should calls without parameters', t => {
issueLinks.linkIssues({
type: undefined,
inwardIssue: undefined,
outwardIssue: undefined,
type: {},
inwardIssue: {},
outwardIssue: {},
});

t.truthy(sendRequestStub.calledOnce);
Expand All @@ -19,8 +19,8 @@ test('linkIssues should calls without parameters', t => {

t.deepEqual(callArgument.data, {
comment: undefined,
inwardIssue: undefined,
outwardIssue: undefined,
type: undefined,
inwardIssue: {},
outwardIssue: {},
type: {},
});
});
2 changes: 1 addition & 1 deletion tests/unit/version2/issuePriorities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as sinon from 'sinon';
import test from 'ava';
import { IssuePriorities, Version2Client } from '../../../src/version2';

const client = new Version2Client({ host: 'http://localhost', newErrorHandling: true });
const client = new Version2Client({ host: 'http://localhost' });
const sendRequestStub = sinon.stub(client, 'sendRequest');
const issuePriorities = new IssuePriorities(client);

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/version2/issueRemoteLinks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as sinon from 'sinon';
import test from 'ava';
import { IssueRemoteLinks, Version2Client } from '../../../src/version2';

const client = new Version2Client({ host: 'http://localhost', newErrorHandling: true });
const client = new Version2Client({ host: 'http://localhost' });
const sendRequestStub = sinon.stub(client, 'sendRequest');
const issueRemoteLinks = new IssueRemoteLinks(client);

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/version2/issueSearch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as sinon from 'sinon';
import test from 'ava';
import { IssueSearch, Version2Client } from '../../../src/version2';

const config = { host: 'http://localhost', newErrorHandling: true };
const config = { host: 'http://localhost' };

test('should be defined', t => {
t.truthy(!!IssueSearch);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/version2/issueVotes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IssueVotes } from '../../../src/version2';
import test from 'ava';
import { Version2Client } from '../../../src';

const client = new Version2Client({ host: 'http://localhost', newErrorHandling: true });
const client = new Version2Client({ host: 'http://localhost' });
const sendRequestStub = sinon.stub(client, 'sendRequest');
const issueVote = new IssueVotes(client);

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/version2/issueWatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import test from 'ava';
import { Version2Client } from '../../../src';

test('addWatcher should accept accountId', t => {
const client = new Version2Client({ host: 'http://localhost', newErrorHandling: true });
const client = new Version2Client({ host: 'http://localhost' });
const sendRequestStub = sinon.stub(client, 'sendRequest');

client.issueWatchers.addWatcher({ issueIdOrKey: '', accountId: '101010' });
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/version2/issues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as sinon from 'sinon';
import test from 'ava';
import { Version2Client } from '../../../src';

const config = { host: 'http://localhost', newErrorHandling: true };
const config = { host: 'http://localhost' };

test('createIssue should accept follow parameters', t => {
const client = new Version2Client(config);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/version2/myself.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as sinon from 'sinon';
import test from 'ava';
import { Myself, Version2Client } from '../../../src/version2';

const client = new Version2Client({ host: 'http://localhost', newErrorHandling: true });
const client = new Version2Client({ host: 'http://localhost' });
const sendRequestStub = sinon.stub(client, 'sendRequest');
const myself = new Myself(client);

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/version2/projectVersions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as sinon from 'sinon';
import test from 'ava';
import { ProjectVersions, Version2Client } from '../../../src/version2';

const config = { host: 'http://localhost', newErrorHandling: true };
const config = { host: 'http://localhost' };

test('should be defined', t => {
t.truthy(!!ProjectVersions);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/version2/workflowStatuses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as sinon from 'sinon';
import test from 'ava';
import { Version2Client, WorkflowStatuses } from '../../../src/version2';

const client = new Version2Client({ host: 'http://localhost', newErrorHandling: true });
const client = new Version2Client({ host: 'http://localhost' });
const sendRequestStub = sinon.stub(client, 'sendRequest');
const workflowStatuses = new WorkflowStatuses(client);

Expand Down
Loading

0 comments on commit 9cc1695

Please sign in to comment.