import { useCallback } from 'react' ; import { errorApiRef , useApi } from '@backstage/core-plugin-api' ; import { useAsyncFn } from 'react-use' ; import { buildKiteApiRef } from '../api' ; export const useLog = ( url ) => { const api = useApi ( buildKiteApiRef ) ; const errorApi = useApi ( errorApiRef ) ; const getLogs = useCallback ( async ( ) => { try { const build = await api . getLog ( url ) ; return Promise . resolve ( build ) ; } catch ( e ) { errorApi . post ( e ) ; return Promise . reject ( e ) ; } } , [ url , api , errorApi ] ) ; const [ state , fetchLogs ] = useAsyncFn ( ( ) => getLogs ( ) , [ getLogs , ] ) ; return { value : state . value , error : state . error , fetchLogs } ; } ;