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.
This commit is contained in:
nguyentrungthat 2026-01-17 10:41:51 +07:00
parent a88ff44ebd
commit c86824e589
1 changed files with 7 additions and 7 deletions

View File

@ -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',
},
],