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

mongodb-js / mongodb-mcp-server / 14793258815

02 May 2025 10:12AM UTC coverage: 72.437% (-2.2%) from 74.619%
14793258815

push

github

web-flow
Merge branch 'main' into main

173 of 324 branches covered (53.4%)

Branch coverage included in aggregate %.

44 of 72 new or added lines in 2 files covered. (61.11%)

3 existing lines in 2 files now uncovered.

689 of 866 relevant lines covered (79.56%)

38.99 hits per line

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

60.53
/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 apiError?: ApiError
3✔
7
    ) {
8
        super(message);
3✔
9
        this.name = "ApiClientError";
3✔
10
    }
11

12
    static async fromResponse(
13
        response: Response,
14
        message: string = `error calling Atlas API`
×
15
    ): Promise<ApiClientError> {
NEW
16
        const err = await this.extractError(response);
×
17

NEW
18
        return this.fromError(response, err, message);
×
19
    }
20

21
    static fromError(
22
        response: Response,
23
        error?: ApiError | string | Error,
24
        message: string = `error calling Atlas API`
3✔
25
    ): ApiClientError {
26
        const errorMessage = this.buildErrorMessage(error);
3✔
27

28
        const apiError = typeof error === "object" && !(error instanceof Error) ? error : undefined;
3!
29

30
        return new ApiClientError(`[${response.status} ${response.statusText}] ${message}: ${errorMessage}`, apiError);
3✔
31
    }
32

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

45
    private static buildErrorMessage(error?: string | ApiError | Error): string {
46
        let errorMessage: string = "unknown error";
3✔
47

48
        if (error instanceof Error) {
3!
NEW
49
            return error.message;
×
50
        }
51

52
        //eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
53
        switch (typeof error) {
3!
54
            case "object":
55
                errorMessage = error.reason || "unknown error";
3!
56
                if (error.detail && error.detail.length > 0) {
3✔
57
                    errorMessage = `${errorMessage}; ${error.detail}`;
3✔
58
                }
59
                break;
3✔
60
            case "string":
NEW
61
                errorMessage = error;
×
NEW
62
                break;
×
63
        }
64

65
        return errorMessage.trim();
3✔
66
    }
67
}
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