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:
parent
a88ff44ebd
commit
c86824e589
|
|
@ -1,13 +1,14 @@
|
||||||
import type { HttpContext } from '@adonisjs/core/http'
|
import type { HttpContext } from '@adonisjs/core/http'
|
||||||
import axios from 'axios'
|
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 {
|
export default class HealCheckController {
|
||||||
// GET /health-check
|
// GET /health-check
|
||||||
async check({}: HttpContext) {
|
async check({}: HttpContext) {
|
||||||
try {
|
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 = {
|
const header = {
|
||||||
Authorization: 'Bearer ' + process.env.ERP_TOKEN,
|
Authorization: 'Bearer ' + process.env.ERP_TOKEN,
|
||||||
}
|
}
|
||||||
|
|
@ -64,7 +65,7 @@ export default class HealCheckController {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
code: resWiki.status,
|
code: 200,
|
||||||
data: [
|
data: [
|
||||||
{
|
{
|
||||||
name: 'wiki',
|
name: 'wiki',
|
||||||
|
|
@ -82,18 +83,17 @@ export default class HealCheckController {
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
|
||||||
return {
|
return {
|
||||||
code: 200,
|
code: 200,
|
||||||
data: [
|
data: [
|
||||||
{
|
{
|
||||||
name: 'wiki',
|
name: 'wiki',
|
||||||
status: false,
|
status: error?.response?.config?.url?.includes(linkWiki) ? false : true,
|
||||||
message: error?.message || 'Checking api wiki fail',
|
message: error?.message || 'Checking api wiki fail',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'update-note-sn',
|
name: 'update-note-sn',
|
||||||
status: false,
|
status: error?.response?.config?.url?.includes(remoteUrl) ? false : true,
|
||||||
message: error?.message || 'Checking api update note SN fail',
|
message: error?.message || 'Checking api update note SN fail',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue