From 773480a40c4703623bbb549a4622f2bee5417cf9 Mon Sep 17 00:00:00 2001 From: Rio Le Date: Tue, 4 Jul 2023 09:10:26 +0000 Subject: [PATCH 1/3] Fix: add try catch block to handle got error --- src/module/base.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/module/base.ts b/src/module/base.ts index cc9cf2f..b45317f 100644 --- a/src/module/base.ts +++ b/src/module/base.ts @@ -1,24 +1,27 @@ -import got from 'got'; -import WhmcsApi from '..'; +import got from "got"; +import WhmcsApi from ".."; export abstract class BaseModule { - async request(methodName: string, options?: any): Promise { options.identifier = WhmcsApi.options.identifier; options.secret = WhmcsApi.options.secret; options.action = methodName; - options.responsetype = 'json'; + options.responsetype = "json"; return new Promise(async (resolve, reject) => { - const res = await got(WhmcsApi.options.apiUrl, { - method: 'post', - form: options - }); + try { + const res = await got(WhmcsApi.options.apiUrl, { + method: "post", + form: options, + }); - const data = JSON.parse(res.body); + const data = JSON.parse(res.body); - if (data.result != "success") return reject(data); - resolve(data); + if (data.result != "success") return reject(data); + resolve(data); + } catch (error) { + reject(error); + } }); } -} \ No newline at end of file +} From acd60ab226d755af9fb44ec42d5d270ec2ecf296 Mon Sep 17 00:00:00 2001 From: Sam Hoque <30783651+SamHoque@users.noreply.github.com> Date: Thu, 2 Nov 2023 20:49:35 +0700 Subject: [PATCH 2/3] =?UTF-8?q?VOC-203:=20=E2=9C=A8=20Implemented=20abilit?= =?UTF-8?q?y=20to=20call=20custom=20endpoints?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- src/index.ts | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 76add87..5deb29a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules -dist \ No newline at end of file +dist +.idea/ \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index f4fe9dc..d032424 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,6 +15,7 @@ import { WhmcsSupportService } from "./module/support"; import { WhmcsSystemService } from "./module/system"; import { WhmcsTicketsService } from "./module/tickets"; import { WhmcsUsersService } from "./module/users"; +import { WhmcsClientCustom } from "./module/custom"; export default class WhmcsApi { @@ -40,4 +41,5 @@ export default class WhmcsApi { public system: WhmcsSystemService = new WhmcsSystemService; public tickets: WhmcsTicketsService = new WhmcsTicketsService; public users: WhmcsUsersService = new WhmcsUsersService; + public custom: WhmcsClientCustom = new WhmcsClientCustom; } \ No newline at end of file From 33635316820f519af5aa2fc261ab920d8d138742 Mon Sep 17 00:00:00 2001 From: Sam Hoque <30783651+SamHoque@users.noreply.github.com> Date: Thu, 2 Nov 2023 20:51:53 +0700 Subject: [PATCH 3/3] =?UTF-8?q?VOC-203:=20=E2=9C=A8=20Implemented=20abilit?= =?UTF-8?q?y=20to=20call=20custom=20endpoints?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/module/custom.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/module/custom.ts diff --git a/src/module/custom.ts b/src/module/custom.ts new file mode 100644 index 0000000..ca97114 --- /dev/null +++ b/src/module/custom.ts @@ -0,0 +1,7 @@ +import {BaseModule} from "./base"; + +export class WhmcsClientCustom extends BaseModule { + public async call(method: string, options: Record): Promise { + return this.request(method, options); + } +} \ No newline at end of file