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

mongodb-js / mongodb-mcp-server / 14855417912

06 May 2025 08:45AM UTC coverage: 70.97%. First build
14855417912

Pull #182

github

web-flow
Merge c45ebc899 into 8760d86c9
Pull Request #182: feat: support flex clusters to atlas tools

177 of 333 branches covered (53.15%)

Branch coverage included in aggregate %.

18 of 40 new or added lines in 5 files covered. (45.0%)

686 of 883 relevant lines covered (77.69%)

36.91 hits per line

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

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

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

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

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

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

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

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

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

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

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

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

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