diff --git a/backend/.eslintrc.js b/backend/.eslintrc.js index 4c53a638f..0e63a9bfe 100644 --- a/backend/.eslintrc.js +++ b/backend/.eslintrc.js @@ -5,7 +5,7 @@ module.exports = { node: true, }, parser: '@typescript-eslint/parser', - plugins: ['prettier', '@typescript-eslint', 'type-graphql', 'jest', 'import', 'n'], + plugins: ['prettier', '@typescript-eslint', 'type-graphql', 'jest', 'import', 'n', 'promise'], extends: [ 'standard', 'eslint:recommended', @@ -142,6 +142,21 @@ module.exports = { 'n/prefer-global/url-search-params': 'error', 'n/prefer-promises/dns': 'error', 'n/prefer-promises/fs': 'error', + // promise + 'promise/catch-or-return': 'error', + 'promise/no-return-wrap': 'error', + 'promise/param-names': 'error', + 'promise/always-return': 'error', + 'promise/no-native': 'off', + 'promise/no-nesting': 'warn', + 'promise/no-promise-in-callback': 'warn', + 'promise/no-callback-in-promise': 'warn', + 'promise/avoid-new': 'warn', + 'promise/no-new-statics': 'error', + 'promise/no-return-in-finally': 'warn', + 'promise/valid-params': 'warn', + 'promise/prefer-await-to-callbacks': 'error', + 'promise/no-multiple-resolved': 'error', }, overrides: [ // only for ts files diff --git a/backend/src/apis/HttpRequest.ts b/backend/src/apis/HttpRequest.ts index 063dfa202..f40d577bd 100644 --- a/backend/src/apis/HttpRequest.ts +++ b/backend/src/apis/HttpRequest.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-argument */ @@ -9,39 +10,35 @@ import { backendLogger as logger } from '@/server/logger' // eslint-disable-next-line @typescript-eslint/no-explicit-any export const apiPost = async (url: string, payload: unknown): Promise => { logger.trace('POST', url, payload) - return axios - .post(url, payload) - .then((result) => { - logger.trace('POST-Response', result) - if (result.status !== 200) { - throw new LogError('HTTP Status Error', result.status) - } - if (result.data.state !== 'success') { - throw new Error(result.data.msg) - } - return { success: true, data: result.data } - }) - .catch((error) => { - return { success: false, data: error.message } - }) + try { + const result = await axios.post(url, payload) + logger.trace('POST-Response', result) + if (result.status !== 200) { + throw new LogError('HTTP Status Error', result.status) + } + if (result.data.state !== 'success') { + throw new LogError(result.data.msg) + } + return { success: true, data: result.data } + } catch (error: any) { + return { success: false, data: error.message } + } } // eslint-disable-next-line @typescript-eslint/no-explicit-any export const apiGet = async (url: string): Promise => { logger.trace('GET: url=' + url) - return axios - .get(url) - .then((result) => { - logger.trace('GET-Response', result) - if (result.status !== 200) { - throw new LogError('HTTP Status Error', result.status) - } - if (!['success', 'warning'].includes(result.data.state)) { - throw new Error(result.data.msg) - } - return { success: true, data: result.data } - }) - .catch((error) => { - return { success: false, data: error.message } - }) + try { + const result = await axios.get(url) + logger.trace('GET-Response', result) + if (result.status !== 200) { + throw new LogError('HTTP Status Error', result.status) + } + if (!['success', 'warning'].includes(result.data.state)) { + throw new LogError(result.data.msg) + } + return { success: true, data: result.data } + } catch (error: any) { + return { success: false, data: error.message } + } }