• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

safe-global / safe-core-sdk / 13326625417

14 Feb 2025 09:46AM UTC coverage: 77.853% (-0.2%) from 78.078%
13326625417

push

github

web-flow
fix(api-kit): import node-fetch dynamically (#1137)

259 of 405 branches covered (63.95%)

Branch coverage included in aggregate %.

0 of 2 new or added lines in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

894 of 1076 relevant lines covered (83.09%)

4.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

16.67
/packages/api-kit/src/utils/httpRequests.ts
1
export enum HttpMethod {
1✔
2
  Get = 'get',
1✔
3
  Post = 'post',
1✔
4
  Delete = 'delete'
1✔
5
}
6

7
interface HttpRequest {
8
  url: string
9
  method: HttpMethod
10
  body?: any
11
}
12

13
export async function sendRequest<T>({ url, method, body }: HttpRequest): Promise<T> {
1✔
NEW
14
  const fetch = await (typeof window === 'undefined'
×
NEW
15
    ? import('node-fetch').then((m) => m.default)
×
16
    : Promise.resolve(window.fetch))
17

UNCOV
18
  const response = await fetch(url, {
×
19
    method,
20
    headers: {
21
      Accept: 'application/json',
22
      'Content-Type': 'application/json'
23
    },
24
    body: JSON.stringify(body)
25
  })
26

27
  let jsonResponse: any
28
  try {
×
29
    jsonResponse = await response.json()
×
30
  } catch (error) {
31
    if (!response.ok) {
×
32
      throw new Error(response.statusText)
×
33
    }
34
  }
35

36
  if (response.ok) {
×
37
    return jsonResponse as T
×
38
  }
39
  if (jsonResponse.data) {
×
40
    throw new Error(jsonResponse.data)
×
41
  }
42
  if (jsonResponse.detail) {
×
43
    throw new Error(jsonResponse.detail)
×
44
  }
45
  if (jsonResponse.message) {
×
46
    throw new Error(jsonResponse.message)
×
47
  }
48
  if (jsonResponse.nonFieldErrors) {
×
49
    throw new Error(jsonResponse.nonFieldErrors)
×
50
  }
51
  if (jsonResponse.delegate) {
×
52
    throw new Error(jsonResponse.delegate)
×
53
  }
54
  if (jsonResponse.safe) {
×
55
    throw new Error(jsonResponse.safe)
×
56
  }
57
  if (jsonResponse.delegator) {
×
58
    throw new Error(jsonResponse.delegator)
×
59
  }
60
  throw new Error(response.statusText)
×
61
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc