Skip to content

Commit

Permalink
fix: update api error
Browse files Browse the repository at this point in the history
  • Loading branch information
phucledien committed Dec 1, 2023
1 parent 59d295f commit a171a78
Show file tree
Hide file tree
Showing 70 changed files with 246 additions and 46 deletions.
1 change: 1 addition & 0 deletions src/adapters/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Webhook extends Fetcher {
curl: res.curl,
description: res.log,
status: res.status ?? 500,
error: res.error,
})
}

Expand Down
1 change: 1 addition & 0 deletions src/commands/activity/index/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export async function render(userDiscordId: string, page = 0) {
description: dataProfile.log,
curl: dataProfile.curl,
status: dataProfile.status ?? 500,
error: dataProfile.error,
})
}
if (!dataProfile)
Expand Down
2 changes: 2 additions & 0 deletions src/commands/airdrop/index/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ async function checkExpiredAirdrop(
curl,
log,
status = 500,
error,
} = await defi.transferV2({
...payload,
sender: await getProfileIdByDiscord(payload.sender),
Expand Down Expand Up @@ -286,6 +287,7 @@ async function checkExpiredAirdrop(
description: log,
curl,
status,
error,
})
}

Expand Down
6 changes: 4 additions & 2 deletions src/commands/alert/add/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ const handlerAlertType: InteractionHandler = async (msgOrInteraction) => {
log,
curl,
status = 500,
error,
} = await Defi.getBinanceCoinPrice(symbol)
if (!ok) {
throw new APIError({ description: log, curl, status })
throw new APIError({ description: log, curl, status, error })
}
const currentPrice = parseFloat(data?.price)
let title = `${getEmoji(
Expand Down Expand Up @@ -237,6 +238,7 @@ const handleFrequency: InteractionHandler = async (msgOrInteraction) => {
log,
curl,
status = 500,
error,
} = await Defi.addAlertPrice({
userDiscordId,
symbol,
Expand All @@ -246,7 +248,7 @@ const handleFrequency: InteractionHandler = async (msgOrInteraction) => {
})

if (!ok) {
throw new APIError({ description: log, curl, status })
throw new APIError({ description: log, curl, status, error })
}

return {
Expand Down
11 changes: 9 additions & 2 deletions src/commands/alert/list/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ export async function handleAlertList({
return null
}

const { ok, data, log, curl, status = 500 } = await defi.getAlertList(userId)
const {
ok,
data,
log,
curl,
status = 500,
error,
} = await defi.getAlertList(userId)
if (!ok) {
throw new APIError({ curl, description: log, status })
throw new APIError({ curl, description: log, status, error })
}

if (!data) {
Expand Down
10 changes: 8 additions & 2 deletions src/commands/alert/remove/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ import { getSuccessEmbed } from "ui/discord/embed"
export const handler: InteractionHandler = async (msgOrInteraction) => {
const interaction = msgOrInteraction as SelectMenuInteraction
const alertId = interaction.values[0]
const { ok, log, curl, status = 500 } = await Defi.removeAlertPrice(alertId)
const {
ok,
log,
curl,
status = 500,
error,
} = await Defi.removeAlertPrice(alertId)

if (!ok) {
throw new APIError({ description: log, curl, status })
throw new APIError({ description: log, curl, status, error })
}

return {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/alert/remove/slash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ const command: SlashCommand = {
log,
curl,
status = 500,
error,
} = await Defi.getAlertList(interaction.user.id)
if (!ok) {
throw new APIError({ description: log, curl, status })
throw new APIError({ description: log, curl, status, error })
}

const options: MessageSelectOptionData[] = []
Expand Down
2 changes: 2 additions & 0 deletions src/commands/alert/remove/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ const command: Command = {
log,
curl,
status = 500,
error,
} = await Defi.getAlertList(msg.author.id)
if (!ok) {
throw new APIError({
msgOrInteraction: msg,
description: log,
curl,
status,
error,
})
}

Expand Down
13 changes: 8 additions & 5 deletions src/commands/balances/index/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export const balanceEmbedProps: Record<
status = 500,
log,
curl,
error,
} = await defi.findWallet(profileId, addressOrAlias)

if (!ok && status !== 404) {
Expand All @@ -118,6 +119,7 @@ export const balanceEmbedProps: Record<
description: log,
curl,
status,
error,
})
}
let address, addressType
Expand Down Expand Up @@ -212,6 +214,7 @@ export async function getBalances(
curl: res.curl,
description: "Couldn't get balance",
status: res.status,
error: res.error,
})
}
let data,
Expand Down Expand Up @@ -319,7 +322,7 @@ async function getTxns(
return []
}
const fetcher = txnsFetcher[type]
const { data, ok, curl, status } = await fetcher(
const { data, ok, curl, status, error } = await fetcher(
profileId,
discordId,
address,
Expand All @@ -332,6 +335,7 @@ async function getTxns(
curl: curl,
description: "Couldn't get txn",
status,
error,
})
}

Expand Down Expand Up @@ -1192,10 +1196,8 @@ export async function unlinkWallet(
addressOrAlias: string,
) {
const profileId = await getProfileIdByDiscord(author.id)
const { ok, status, log, curl } = await profile.disconnectOnChainWallet(
profileId,
addressOrAlias,
)
const { ok, status, log, curl, error } =
await profile.disconnectOnChainWallet(profileId, addressOrAlias)
// wallet not found
if (!ok && status === 404) {
throw new InternalError({
Expand All @@ -1211,6 +1213,7 @@ export async function unlinkWallet(
description: log,
curl,
status: status ?? 500,
error,
})
// remove successfully
const pointingright = getEmoji("ANIMATED_POINTING_RIGHT", true)
Expand Down
1 change: 1 addition & 0 deletions src/commands/config/currency/info/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export async function runCurrencyInfo(
curl: res.curl,
description: res.log,
status: res.status ?? 500,
error: res.error,
})
}
if (!res.data) {
Expand Down
2 changes: 2 additions & 0 deletions src/commands/config/currency/remove/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export async function runCurrencyRemove(guildId: string | null) {
curl: infoRes.curl,
description: infoRes.log,
status: infoRes.status ?? 500,
error: infoRes.error,
})
}

Expand All @@ -39,6 +40,7 @@ export async function runCurrencyRemove(guildId: string | null) {
curl: res.curl,
description: res.log,
status: res.status ?? 500,
error: res.error,
})
}

Expand Down
2 changes: 2 additions & 0 deletions src/commands/config/currency/set/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export async function set(i: CommandInteraction, symbol: string) {
curl: setCurl,
log: setLog,
status = 500,
error,
} = await config.setDefaultCurrency({ symbol, guild_id: i.guildId })

if (!setOk) {
Expand All @@ -33,6 +34,7 @@ export async function set(i: CommandInteraction, symbol: string) {
curl: setCurl,
description: setLog,
status,
error,
})
}

Expand Down
3 changes: 3 additions & 0 deletions src/commands/config/logchannel/info/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default async function (i: CommandInteraction) {
curl: levelUpCfg.curl,
description: levelUpCfg.log,
status: levelUpCfg.status ?? 500,
error: levelUpCfg.error,
})
}

Expand All @@ -23,6 +24,7 @@ export default async function (i: CommandInteraction) {
curl: gmCfg.curl,
description: gmCfg.log,
status: gmCfg.status ?? 500,
error: gmCfg.error,
})
}

Expand All @@ -33,6 +35,7 @@ export default async function (i: CommandInteraction) {
curl: tipCfg.curl,
description: tipCfg.log,
status: tipCfg.status ?? 500,
error: tipCfg.error,
})
}

Expand Down
9 changes: 8 additions & 1 deletion src/commands/config/maxtipped/index/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,19 @@ export default async function run(i: CommandInteraction) {
curl,
log,
status = 500,
error,
} = await config.setTipRangeConfig({
guildId: i.guildId,
max: value,
})
if (!ok)
throw new APIError({ msgOrInteraction: i, curl, description: log, status })
throw new APIError({
msgOrInteraction: i,
curl,
description: log,
status,
error,
})
const embed = getSuccessEmbed({
title: "You have set up successfully",
description: `Changed the maxtipped to: $${value}`,
Expand Down
9 changes: 8 additions & 1 deletion src/commands/config/minrain/index/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,19 @@ export default async function run(i: CommandInteraction) {
curl,
log,
status = 500,
error,
} = await config.setTipRangeConfig({
guildId: i.guildId,
min: value,
})
if (!ok)
throw new APIError({ msgOrInteraction: i, curl, description: log, status })
throw new APIError({
msgOrInteraction: i,
curl,
description: log,
status,
error,
})
const embed = getSuccessEmbed({
title: "You have set up successfully",
description: `Changed the minrain to: $${value}`,
Expand Down
4 changes: 4 additions & 0 deletions src/commands/config/moniker/list/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,30 @@ export async function handleMonikerList(
log: defaultLog,
curl: defaultCurl,
status: defaultStatus = 500,
error: defaultError,
} = await config.getDefaultMoniker()
const {
ok: guildMonikerOk,
data: _guildMonikers,
log: guildLog,
curl: guildCurl,
status: guildStatus = 500,
error: guildError,
} = await config.getMonikerConfig(guildId)
if (!guildMonikerOk) {
throw new APIError({
description: guildLog,
curl: guildCurl,
status: guildStatus,
error: guildError,
})
}
if (!defaultMonikerOk) {
throw new APIError({
description: defaultLog,
curl: defaultCurl,
status: defaultStatus,
error: defaultError,
})
}

Expand Down
3 changes: 2 additions & 1 deletion src/commands/config/moniker/remove/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ export const handleRemoveMoniker = async (
log,
curl,
status = 500,
error,
} = await config.deleteMonikerConfig(payload)
if (!ok) {
throw new APIError({ description: log, curl, status })
throw new APIError({ description: log, curl, status, error })
}
return {
messageOptions: {
Expand Down
10 changes: 8 additions & 2 deletions src/commands/config/moniker/set/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@ export const handleSetMoniker = async (
},
}
}
const { ok, log, curl, status = 500 } = await config.setMonikerConfig(payload)
const {
ok,
log,
curl,
status = 500,
error,
} = await config.setMonikerConfig(payload)
if (!ok) {
throw new APIError({ description: log, curl, status })
throw new APIError({ description: log, curl, status, error })
}
return {
messageOptions: {
Expand Down
1 change: 1 addition & 0 deletions src/commands/config/tiprange/info/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export async function runTipRangeInfo(
curl: res.curl,
description: res.log,
status: res.status ?? 500,
error: res.error,
})
}
if (!res.data) {
Expand Down
2 changes: 2 additions & 0 deletions src/commands/config/tiprange/remove/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export async function runTipRangeRemove(guildId: string | null) {
curl: infoRes.curl,
description: infoRes.log,
status: infoRes.status ?? 500,
error: infoRes.error,
})
}

Expand All @@ -39,6 +40,7 @@ export async function runTipRangeRemove(guildId: string | null) {
curl: res.curl,
description: res.log,
status: res.status ?? 500,
error: res.error,
})
}

Expand Down
Loading

0 comments on commit a171a78

Please sign in to comment.