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

mongodb-js / mongodb-mcp-server / 14759019823

30 Apr 2025 04:03PM UTC coverage: 69.476%. First build
14759019823

Pull #176

github

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

148 of 306 branches covered (48.37%)

Branch coverage included in aggregate %.

33 of 69 new or added lines in 2 files covered. (47.83%)

635 of 821 relevant lines covered (77.34%)

37.46 hits per line

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

11.76
/src/common/atlas/apiClientError.ts
1
import { ApiError } from "./openapi.js";
2

3
export class ApiClientError extends Error {
4
    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`
×
16
    ): Promise<ApiClientError> {
NEW
17
        const err = await this.extractError(response);
×
18

NEW
19
        const errorMessage = this.buildErrorMessage(err);
×
20

NEW
21
        const body = err && typeof err === "object" ? err : undefined;
×
22

NEW
23
        return new ApiClientError(
×
24
            `[${response.status} ${response.statusText}] ${message}: ${errorMessage}`,
25
            response,
26
            body
27
        );
28
    }
29

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

42
    private static buildErrorMessage(error?: string | ApiError): string {
43
        let errorMessage: string = "unknown error";
×
44

45
        //eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
NEW
46
        switch (typeof error) {
×
47
            case "object":
NEW
48
                errorMessage = error.reason || "unknown error";
×
NEW
49
                if (error.detail && error.detail.length > 0) {
×
NEW
50
                    errorMessage = `${errorMessage}; ${error.detail}`;
×
51
                }
NEW
52
                break;
×
53
            case "string":
NEW
54
                errorMessage = error;
×
NEW
55
                break;
×
56
        }
57

NEW
58
        return errorMessage.trim();
×
59
    }
60
}
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