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

mongodb-js / mongodb-mcp-server / 14793511077

02 May 2025 10:30AM UTC coverage: 72.46%. First build
14793511077

Pull #187

github

fmenezes
fix: update codeowners
Pull Request #187: fix: db user test error

173 of 324 branches covered (53.4%)

Branch coverage included in aggregate %.

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

690 of 867 relevant lines covered (79.58%)

37.61 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