PluginProbe
Extendify / 3.2.2
Extendify v3.2.2
3.2.2 3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 All 128 releases
extendify / src / AutoLaunch / fetchers / get-launch-decisions.js

get-launch-decisions.js in Extendify 3.2.2, at src/AutoLaunch/fetchers/get-launch-decisions.js

46 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { getLaunchDecisionsShape } from '@auto-launch/fetchers/shape';
2 import {
3 failWithFallback,
4 fetchWithTimeout,
5 retryTwice,
6 } from '@auto-launch/functions/helpers';
7 import { AI_HOST } from '@constants';
8 import { digest } from '@shared/api/digest';
9 import { reqDataBasics } from '@shared/lib/data';
10
11 const fallback = {
12 launchDecisions: { navExtras: 'none', navButtonLabel: '' },
13 };
14 const url = `${AI_HOST}/api/launch-decisions`;
15 const method = 'POST';
16 const headers = { 'Content-Type': 'application/json' };
17
18 export const handleLaunchDecisions = async ({ siteProfile }) => {
19 const body = JSON.stringify({ ...reqDataBasics, siteProfile });
20
21 const response = await retryTwice(() =>
22 fetchWithTimeout(url, { method, headers, body }),
23 ).catch((error) => {
24 return { ok: false, statusText: error.message, status: 0 };
25 });
26
27 if (!response?.ok) {
28 digest({
29 error: {
30 message: response.statusText,
31 name: 'FetchError',
32 status: response.status,
33 },
34 details: { source: 'auto-launch', caller: 'handleLaunchDecisions' },
35 });
36 return fallback;
37 }
38
39 return failWithFallback(
40 async () => ({
41 launchDecisions: getLaunchDecisionsShape.parse(await response.json()),
42 }),
43 fallback,
44 );
45 };
46