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

mongodb-js / mongodb-mcp-server / 14759002067

30 Apr 2025 04:02PM UTC coverage: 73.483%. First build
14759002067

Pull #176

github

fmenezes
fix: type errors
Pull Request #176: fix: improve api error messages

153 of 284 branches covered (53.87%)

Branch coverage included in aggregate %.

25 of 33 new or added lines in 2 files covered. (75.76%)

634 of 787 relevant lines covered (80.56%)

39.21 hits per line

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

83.33
/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 { errorMessage, body } = await this.extractErrorMessage(response);
1✔
18

19
        return new ApiClientError(`${message}: ${errorMessage}`, response, body);
1✔
20
    }
21

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

41
        errorMessage = `[${response.status} ${response.statusText}] ${errorMessage.trim()}`;
1✔
42

43
        return {
1✔
44
            errorMessage,
45
            body,
46
        };
47
    }
48
}
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