Skip to content

Commit 657ebf8

Browse files
author
Alejandro Fernández Gómez
committed
Parse API response
1 parent a8c3927 commit 657ebf8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

x-pack/plugins/infra/public/hooks/use_trial_status.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7+
import { boolean } from 'io-ts';
8+
79
import { useState } from 'react';
810
import { useKibana } from '../../../../../src/plugins/kibana_react/public';
911
import { API_BASE_PATH as LICENSE_MANAGEMENT_API_BASE_PATH } from '../../../license_management/common/constants';
1012
import { useTrackedPromise } from '../utils/use_tracked_promise';
13+
import { decodeOrThrow } from '../../common/runtime_types';
1114

1215
interface UseTrialStatusState {
1316
loadState: 'uninitialized' | 'pending' | 'resolved' | 'rejected';
@@ -22,7 +25,8 @@ export function useTrialStatus(): UseTrialStatusState {
2225
const [loadState, checkTrialAvailability] = useTrackedPromise(
2326
{
2427
createPromise: async () => {
25-
return await services.http.get(`${LICENSE_MANAGEMENT_API_BASE_PATH}/start_trial`);
28+
const response = await services.http.get(`${LICENSE_MANAGEMENT_API_BASE_PATH}/start_trial`);
29+
return decodeOrThrow(boolean)(response);
2630
},
2731
onResolve: (response) => {
2832
setIsTrialAvailable(response);

0 commit comments

Comments
 (0)