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

mongodb-js / mongodb-mcp-server / 14752073629

30 Apr 2025 10:01AM UTC coverage: 73.983%. First build
14752073629

Pull #176

github

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

153 of 281 branches covered (54.45%)

Branch coverage included in aggregate %.

12 of 15 new or added lines in 1 file covered. (80.0%)

629 of 776 relevant lines covered (81.06%)

39.79 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 {
NEW
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