Skip to content

Commit

Permalink
Fix HealthCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
crni99 committed Jan 9, 2025
1 parent 16e17cf commit f96acf3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/components/common/HealthCheck.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import React from 'react';
import useFetch from "../../hooks/useFetch";
import Alert from '../common/Alert';
import { Entities } from '../../utils/const.js';

// Not working properly if there isn't connection with the API
export default function HealthCheck() {
const { data, error, isLoading, isError } = useFetch('HealthCheck', null);
const { data, dataExist, error, isLoading, isError } = useFetch(Entities.HEALTH_CHECKS, null, null, null);

const extractErrorMessage = (error) => {
if (error && error.message) {
return error.message;
}
return "An unknown error occurred";
};

return (
<div className="container mt-5">
Expand All @@ -14,8 +22,8 @@ export default function HealthCheck() {
<div className="form-horizontal">
<div className="form-group">
{isLoading && <Alert alertType="info" alertText="Loading..." />}
{isError && error && <Alert alertType="error" alertText={error} />}
{data && !isError && !error ? (
{isError && error && <Alert alertType="error" alertText={extractErrorMessage(error)} />}
{data && dataExist && !isError && !error ? (
<div>
<dl className="row">
<dt className="col-sm-2">Status</dt>
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/useFetch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ export default function useFetch(dataType, dataId, page = 1, triggerFetch) {
}
break;

case Entities.HEALTH_CHECKS:
return `${apiUrl}/${dataType}`;

default:
url = `${apiUrl}/${dataType}?${paginationParams}`;
break;
Expand Down
1 change: 1 addition & 0 deletions src/utils/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export const Entities = {
PILOTS: 'Pilots',
PLANE_TICKETS: 'PlaneTickets',
TRAVEL_CLASSES: 'TravelClasses',
HEALTH_CHECKS: 'HealthCheck',
};

0 comments on commit f96acf3

Please sign in to comment.