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

safe-global / safe-core-sdk / 11029255652

25 Sep 2024 08:18AM UTC coverage: 77.534%. Remained the same
11029255652

push

github

dasanra
chore: set release versions

261 of 410 branches covered (63.66%)

Branch coverage included in aggregate %.

978 of 1188 relevant lines covered (82.32%)

3.49 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
import fetch from 'node-fetch'
1✔
2

3
export enum HttpMethod {
1✔
4
  Get = 'get',
1✔
5
  Post = 'post',
1✔
6
  Delete = 'delete'
1✔
7
}
8

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

15
export async function sendRequest<T>({ url, method, body }: HttpRequest): Promise<T> {
1✔
16
  const response = await fetch(url, {
×
17
    method,
18
    headers: {
19
      Accept: 'application/json',
20
      'Content-Type': 'application/json'
21
    },
22
    body: JSON.stringify(body)
23
  })
24

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

34
  if (response.ok) {
×
35
    return jsonResponse as T
×
36
  }
37
  if (jsonResponse.data) {
×
38
    throw new Error(jsonResponse.data)
×
39
  }
40
  if (jsonResponse.detail) {
×
41
    throw new Error(jsonResponse.detail)
×
42
  }
43
  if (jsonResponse.message) {
×
44
    throw new Error(jsonResponse.message)
×
45
  }
46
  if (jsonResponse.nonFieldErrors) {
×
47
    throw new Error(jsonResponse.nonFieldErrors)
×
48
  }
49
  if (jsonResponse.delegate) {
×
50
    throw new Error(jsonResponse.delegate)
×
51
  }
52
  if (jsonResponse.safe) {
×
53
    throw new Error(jsonResponse.safe)
×
54
  }
55
  if (jsonResponse.delegator) {
×
56
    throw new Error(jsonResponse.delegator)
×
57
  }
58
  throw new Error(response.statusText)
×
59
}
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

© 2025 Coveralls, Inc