github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/webapp/javascript/services/serviceDiscovery.ts (about)

     1  import { Result } from '@webapp/util/fp';
     2  import { Target, targetsModel } from '@webapp/models/targets';
     3  import type { ZodError } from 'zod';
     4  import { request, parseResponse } from './base';
     5  import type { RequestError } from './base';
     6  
     7  /* eslint-disable import/prefer-default-export */
     8  export async function fetchTargets(): Promise<
     9    Result<Target[], RequestError | ZodError>
    10  > {
    11    const response = await request('targets');
    12  
    13    if (response.isOk) {
    14      return parseResponse(response, targetsModel);
    15    }
    16  
    17    return Result.err<Target[], RequestError>(response.error);
    18  }