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

mongodb-js / mongodb-mcp-server / 16275099623

14 Jul 2025 06:42PM UTC coverage: 77.524% (+2.3%) from 75.27%
16275099623

Pull #363

github

web-flow
Merge 3f10cbde7 into 184841400
Pull Request #363: chore(tests): switch to vitest

499 of 688 branches covered (72.53%)

Branch coverage included in aggregate %.

0 of 26 new or added lines in 2 files covered. (0.0%)

291 existing lines in 26 files now uncovered.

2833 of 3610 relevant lines covered (78.48%)

28.87 hits per line

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

85.9
/src/common/atlas/apiClientError.ts
1
import { ApiError } from "./openapi.js";
2

3
export class ApiClientError extends Error {
2✔
4
    private constructor(
2✔
5
        message: string,
7✔
6
        public readonly response: Response,
7✔
7
        public readonly apiError?: ApiError
7✔
8
    ) {
7✔
9
        super(message);
7✔
10
        this.name = "ApiClientError";
7✔
11
    }
7✔
12

13
    static async fromResponse(
2✔
14
        response: Response,
3✔
15
        message: string = `error calling Atlas API`
3✔
16
    ): Promise<ApiClientError> {
3✔
17
        const err = await this.extractError(response);
3✔
18

19
        return this.fromError(response, err, message);
3✔
20
    }
3✔
21

22
    static fromError(
2✔
23
        response: Response,
7✔
24
        error?: ApiError | string | Error,
7✔
25
        message: string = `error calling Atlas API`
7✔
26
    ): ApiClientError {
7✔
27
        const errorMessage = this.buildErrorMessage(error);
7✔
28

29
        const apiError = typeof error === "object" && !(error instanceof Error) ? error : undefined;
7!
30

31
        return new ApiClientError(
7✔
32
            `[${response.status} ${response.statusText}] ${message}: ${errorMessage}`,
7✔
33
            response,
7✔
34
            apiError
7✔
35
        );
7✔
36
    }
7✔
37

38
    private static async extractError(response: Response): Promise<ApiError | string | undefined> {
2✔
39
        try {
3✔
40
            return (await response.json()) as ApiError;
3✔
41
        } catch {
3✔
42
            try {
3✔
43
                return await response.text();
3✔
44
            } catch {
3!
45
                return undefined;
×
UNCOV
46
            }
×
47
        }
3✔
48
    }
3✔
49

50
    private static buildErrorMessage(error?: string | ApiError | Error): string {
2✔
51
        let errorMessage: string = "unknown error";
7✔
52

53
        if (error instanceof Error) {
7!
54
            return error.message;
×
UNCOV
55
        }
×
56

57
        //eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
58
        switch (typeof error) {
7✔
59
            case "object":
7✔
60
                errorMessage = error.reason || "unknown error";
4!
61
                if (error.detail && error.detail.length > 0) {
4✔
62
                    errorMessage = `${errorMessage}; ${error.detail}`;
4✔
63
                }
4✔
64
                break;
4✔
65
            case "string":
7!
66
                errorMessage = error;
3✔
67
                break;
3✔
68
        }
7✔
69

70
        return errorMessage.trim();
7✔
71
    }
7✔
72
}
2✔
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