From c86824e589b8e6cf414928381da2b9bae98b79c3 Mon Sep 17 00:00:00 2001 From: nguyentrungthat <80239428+nguentrungthat@users.noreply.github.com> Date: Sat, 17 Jan 2026 10:41:51 +0700 Subject: [PATCH] Refactor health check controller and improve error handling Moves LINK_WIKI and ERP_URL constants outside the check method for reuse. Updates error handling to set status based on which API call failed, and removes console logging for cleaner output. Always returns code 200 for consistency. --- BACKEND/app/controllers/healcheck_controller.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/BACKEND/app/controllers/healcheck_controller.ts b/BACKEND/app/controllers/healcheck_controller.ts index 77241d0..cf315ff 100644 --- a/BACKEND/app/controllers/healcheck_controller.ts +++ b/BACKEND/app/controllers/healcheck_controller.ts @@ -1,13 +1,14 @@ import type { HttpContext } from '@adonisjs/core/http' import axios from 'axios' +const linkWiki = + process.env.LINK_WIKI || 'https://logs.danielvu.com/api/wiki/page/insert?title=Dev_test' +const remoteUrl = process.env.ERP_URL || 'https://stage.nswteam.net' + export default class HealCheckController { // GET /health-check async check({}: HttpContext) { try { - const linkWiki = - process.env.LINK_WIKI || 'https://logs.danielvu.com/api/wiki/page/insert?title=Dev_test' - const remoteUrl = process.env.ERP_URL || 'https://stage.nswteam.net' const header = { Authorization: 'Bearer ' + process.env.ERP_TOKEN, } @@ -64,7 +65,7 @@ export default class HealCheckController { } ) return { - code: resWiki.status, + code: 200, data: [ { name: 'wiki', @@ -82,18 +83,17 @@ export default class HealCheckController { ], } } catch (error) { - console.log(error) return { code: 200, data: [ { name: 'wiki', - status: false, + status: error?.response?.config?.url?.includes(linkWiki) ? false : true, message: error?.message || 'Checking api wiki fail', }, { name: 'update-note-sn', - status: false, + status: error?.response?.config?.url?.includes(remoteUrl) ? false : true, message: error?.message || 'Checking api update note SN fail', }, ],