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

mongodb-js / mongodb-mcp-server / 14761320963

30 Apr 2025 06:10PM UTC coverage: 69.618%. First build
14761320963

Pull #182

github

fmenezes
feat: support flex clusters to atlas tools
Pull Request #182: feat: support flex clusters to atlas tools

161 of 315 branches covered (51.11%)

Branch coverage included in aggregate %.

61 of 110 new or added lines in 6 files covered. (55.45%)

641 of 837 relevant lines covered (76.58%)

36.79 hits per line

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

60.53
/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 apiError?: ApiError
1✔
7
    ) {
8
        super(message);
1✔
9
        this.name = "ApiClientError";
1✔
10
    }
11

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

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

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

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

30
        return new ApiClientError(`[${response.status} ${response.statusText}] ${message}: ${errorMessage}`, apiError);
1✔
31
    }
32

33
    private static async extractError(response: Response): Promise<ApiError | string | undefined> {
34
        try {
×
NEW
35
            return (await response.json()) as ApiError;
×
36
        } catch {
NEW
37
            try {
×
NEW
38
                return await response.text();
×
39
            } catch {
NEW
40
                return undefined;
×
41
            }
42
        }
43
    }
44

45
    private static buildErrorMessage(error?: string | ApiError | Error): string {
46
        let errorMessage: string = "unknown error";
1✔
47

48
        if (error instanceof Error) {
1!
NEW
49
            return error.message;
×
50
        }
51

52
        //eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
53
        switch (typeof error) {
1!
54
            case "object":
55
                errorMessage = error.reason || "unknown error";
1!
56
                if (error.detail && error.detail.length > 0) {
1✔
57
                    errorMessage = `${errorMessage}; ${error.detail}`;
1✔
58
                }
59
                break;
1✔
60
            case "string":
NEW
61
                errorMessage = error;
×
NEW
62
                break;
×
63
        }
64

65
        return errorMessage.trim();
1✔
66
    }
67
}
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