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

nktkas / hyperliquid / 21190802342

20 Jan 2026 10:10PM UTC coverage: 95.464% (+0.01%) from 95.453%
21190802342

push

github

web-flow
feat(info/userNonFundingLedgerUpdates): add new update types for UserNonFundingLedgerUpdatesResponse (#112)

655 of 874 branches covered (74.94%)

Branch coverage included in aggregate %.

42 of 42 new or added lines in 1 file covered. (100.0%)

32 existing lines in 5 files now uncovered.

13276 of 13719 relevant lines covered (96.77%)

1187.37 hits per line

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

62.69
/src/api/exchange/_methods/_base/errors.ts
1
import { HyperliquidError } from "../../../../_base.ts";
382✔
2

3
// =============================================================
4
// Error Detection (Duck Typing)
5
// =============================================================
6

7
/** Check if value has an error property. */
8
function hasError(value: unknown): value is { error: string } {
382✔
UNCOV
9
  return typeof value === "object" && value !== null &&
✔
UNCOV
10
    "error" in value && typeof value.error === "string";
×
11
}
889✔
12

13
/** Check if response has error status. */
14
function hasErrorStatus(response: unknown): response is { status: "err"; response: string } {
382✔
15
  return typeof response === "object" && response !== null &&
1,000✔
16
    "status" in response && response.status === "err";
1,000✔
17
}
1,000✔
18

19
/** Check if response has statuses array with errors. */
20
function hasStatusesWithErrors(response: unknown): boolean {
382✔
21
  if (typeof response !== "object" || response === null) return false;
×
22
  const r = response as { response?: { data?: { statuses?: unknown[] } } };
826✔
23
  const statuses = r.response?.data?.statuses;
826✔
24
  return Array.isArray(statuses) && statuses.some(hasError);
826✔
25
}
826✔
26

27
/** Check if response has single status with error. */
28
function hasSingleStatusWithError(response: unknown): boolean {
382✔
29
  if (typeof response !== "object" || response === null) return false;
×
30
  const r = response as { response?: { data?: { status?: unknown } } };
826✔
31
  return hasError(r.response?.data?.status);
826✔
32
}
826✔
33

34
/** Extract error message from response using duck typing. */
35
function extractErrorMessage(response: unknown): string | undefined {
382✔
36
  if (hasErrorStatus(response)) {
469✔
37
    return response.response;
469✔
38
  }
469!
39

UNCOV
40
  const r = response as { response?: { data?: { statuses?: unknown[]; status?: unknown } } };
×
41

UNCOV
42
  if (Array.isArray(r.response?.data?.statuses)) {
×
UNCOV
43
    const errors = r.response.data.statuses.reduce<string[]>((acc, status, index) => {
×
UNCOV
44
      if (hasError(status)) acc.push(`Order ${index}: ${status.error}`);
×
UNCOV
45
      return acc;
×
UNCOV
46
    }, []);
×
UNCOV
47
    if (errors.length > 0) return errors.join(", ");
×
UNCOV
48
  }
×
49

50
  if (hasError(r.response?.data?.status)) {
×
51
    return r.response.data.status.error;
×
52
  }
×
53

54
  return undefined;
×
55
}
469✔
56

57
// =============================================================
58
// Error Classes
59
// =============================================================
60

61
/** Thrown when Exchange API returns an error response. */
62
export class ApiRequestError extends HyperliquidError {
382✔
63
  readonly response: unknown;
382✔
64

65
  constructor(response: unknown) {
382✔
66
    const message = extractErrorMessage(response) ||
×
67
      "An unknown error occurred while processing an API request. See `response` for more details.";
×
68
    super(message);
469✔
69
    this.name = "ApiRequestError";
469✔
70
    this.response = response;
469✔
71
  }
469✔
72
}
382✔
73

74
// =============================================================
75
// Assertions
76
// =============================================================
77

78
/** Assert that response is successful, throw ApiRequestError otherwise. */
79
export function assertSuccessResponse(response: unknown): void {
382✔
80
  if (hasErrorStatus(response) || hasStatusesWithErrors(response) || hasSingleStatusWithError(response)) {
913✔
81
    throw new ApiRequestError(response);
1,000✔
82
  }
1,000✔
83
}
913✔
84

85
// =============================================================
86
// Type Utilities
87
// =============================================================
88

89
// deno-lint-ignore ban-types
90
type Prettify<T> = { [K in keyof T]: T[K] } & {};
91

92
/** Exclude error variants from response type. */
93
export type ExcludeErrorResponse<T> = T extends { status: "err" } ? never // with error status
94
  : T extends { response: { data: { statuses: ReadonlyArray<infer S> } } } // with multiple statuses
95
    ? Exclude<S, { error: unknown }> extends never ? never
96
    : Prettify<
97
      Omit<T, "response"> & {
98
        response: Prettify<Omit<T["response"], "data"> & { data: { statuses: Array<Exclude<S, { error: unknown }>> } }>;
99
      }
100
    >
101
  : T extends { response: { data: { status: infer S } } } // with single status
102
    ? S extends { error: unknown } ? never
103
    : Prettify<
104
      Omit<T, "response"> & {
105
        response: Prettify<Omit<T["response"], "data"> & { data: { status: Exclude<S, { error: unknown }> } }>;
106
      }
107
    >
108
  : T;
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