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

mongodb-js / mongodb-mcp-server / 14751742402

30 Apr 2025 09:49AM UTC coverage: 73.938%. First build
14751742402

Pull #176

github

fmenezes
fix: copilot error
Pull Request #176: fix: improve api error messages

154 of 283 branches covered (54.42%)

Branch coverage included in aggregate %.

12 of 14 new or added lines in 1 file covered. (85.71%)

629 of 776 relevant lines covered (81.06%)

39.81 hits per line

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

80.77
/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,
1✔
7
        public readonly body?: ApiError
1✔
8
    ) {
9
        super(message);
1✔
10
        this.name = "ApiClientError";
1✔
11
    }
12

13
    static async fromResponse(
14
        response: Response,
15
        message: string = `error calling Atlas API`
1✔
16
    ): Promise<ApiClientError> {
17
        const { text, body } = await this.extractErrorMessage(response);
1✔
18

19
        const errorMessage =
20
            text.length > 0
1!
21
                ? `${message}: [${response.status} ${response.statusText}] ${text.trim()}`
22
                : `${message}: ${response.status} ${response.statusText}`;
23

24
        return new ApiClientError(errorMessage, response, body);
1✔
25
    }
26

27
    private static async extractErrorMessage(
28
        response: Response
29
    ): Promise<{ text: string; body: ApiError | undefined }> {
30
        let text: string = "";
1✔
31
        let body: ApiError | undefined = undefined;
1✔
32
        try {
1✔
33
            body = (await response.json()) as ApiError;
1✔
34
            text = body.reason || "unknown error";
1!
35
            if (body.detail && body.detail.length > 0) {
1✔
36
                text = `${text}; ${body.detail}`;
1✔
37
            }
38
        } catch {
39
            try {
×
NEW
40
                text = await response.text();
×
41
            } catch {
NEW
42
                text = "";
×
43
            }
44
        }
45

46
        return {
1✔
47
            text,
48
            body,
49
        };
50
    }
51
}
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