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

safe-global / safe-client-gateway / 8630594257

10 Apr 2024 11:38AM UTC coverage: 45.232% (-47.6%) from 92.862%
8630594257

Pull #1369

github

iamacook
Only store signer address in JWT payload
Pull Request #1369: Add `AuthGuard`

293 of 2225 branches covered (13.17%)

Branch coverage included in aggregate %.

4 of 9 new or added lines in 3 files covered. (44.44%)

2495 existing lines in 237 files now uncovered.

3540 of 6249 relevant lines covered (56.65%)

8.62 hits per line

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

56.82
/src/logging/utils.ts
1
import { Request } from 'express';
2
import { get } from 'lodash';
14✔
3

4
const HEADER_IP_ADDRESS = 'X-Real-IP';
14✔
5
const HEADER_SAFE_APP_USER_AGENT = 'Safe-App-User-Agent';
14✔
6

7
export function formatRouteLogMessage(
14✔
8
  statusCode: number,
9
  request: Request,
10
  startTimeMs: number,
11
  detail?: string,
12
): {
13
  chain_id: string | null;
14
  client_ip: string | null;
15
  method: string;
16
  response_time_ms: number;
17
  route: string;
18
  path: string;
19
  safe_app_user_agent: string | null;
20
  status_code: number;
21
  detail: string | null;
22
} {
23
  const clientIp = request.header(HEADER_IP_ADDRESS) ?? null;
18!
24
  const safe_app_user_agent =
25
    request.header(HEADER_SAFE_APP_USER_AGENT) ?? null;
18✔
26
  const chainId = request.params['chainId'] ?? null;
18✔
27

28
  return {
18✔
29
    chain_id: chainId,
30
    client_ip: clientIp,
31
    method: request.method,
32
    response_time_ms: performance.now() - startTimeMs,
33
    route: request.route.path,
34
    path: request.url,
35
    safe_app_user_agent: safe_app_user_agent,
36
    status_code: statusCode,
37
    detail: detail ?? null,
27✔
38
  };
39
}
40

41
/**
42
 * Coerces an unknown value into an {@link Error} with defined {@link message}:
43
 *
44
 * @param thrown - The value to coerce into an {@link Error}
45
 *
46
 * - If the value is an {@link Error}, it is returned as is.
47
 *
48
 * The {@link message} of the returned {@link Error} is otherwise defined as follows:
49
 *
50
 * - If {@link thrown} is a string, it is used as the {@link message}.
51
 * - If {@link thrown} is an object, it tries to get a `message` property and uses it as the {@link message}.
52
 * - If {@link thrown} is an object without a `message` property, it tries to stringify it and use it as the {@link message}.
53
 * - If stringify fails, it converts {@link thrown} to string and uses it as the {@link message}.
54
 *
55
 * @returns {@link Error} containing {@link message}
56
 */
57
export const asError = (thrown: unknown): Error => {
14✔
UNCOV
58
  if (thrown instanceof Error) {
×
UNCOV
59
    return thrown;
×
60
  }
61

62
  let message: string;
63

UNCOV
64
  if (typeof thrown === 'string') {
×
UNCOV
65
    message = thrown;
×
66
  } else {
UNCOV
67
    try {
×
UNCOV
68
      message = get(thrown, 'message') ?? JSON.stringify(thrown);
×
69
    } catch {
UNCOV
70
      message = String(thrown);
×
71
    }
72
  }
73

UNCOV
74
  return new Error(message);
×
75
};
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