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

chvarkov / google-recaptcha / 6bc0973a-9b23-491e-beff-2fe079b7a34f

pending completion
6bc0973a-9b23-491e-beff-2fe079b7a34f

push

circleci

web-flow
Merge pull request #125 from chvarkov/dependabot/npm_and_yarn/word-wrap-1.2.4

build(deps-dev): bump word-wrap from 1.2.3 to 1.2.4

208 of 215 branches covered (96.74%)

Branch coverage included in aggregate %.

346 of 346 relevant lines covered (100.0%)

11.05 hits per line

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

100.0
/src/exceptions/google-recaptcha.exception.ts
1
import { HttpException, HttpStatus } from '@nestjs/common';
14✔
2
import { ErrorCode } from '../enums/error-code';
14✔
3

4
export class GoogleRecaptchaException extends HttpException {
14✔
5
        constructor(public readonly errorCodes: ErrorCode[], errorMessage?: string) {
31✔
6
                super(
31✔
7
                        errorMessage || GoogleRecaptchaException.getErrorMessage(errorCodes[0]),
55✔
8
                        GoogleRecaptchaException.getErrorStatus(errorCodes[0])
9
                );
10
        }
11

12
        private static getErrorMessage(errorCode: ErrorCode): string {
13
                switch (errorCode) {
24✔
14
                        case ErrorCode.InvalidInputResponse:
15
                                return 'The response parameter is invalid or malformed.';
3✔
16

17
                        case ErrorCode.MissingInputResponse:
18
                                return 'The response parameter is missing.';
1✔
19
                        case ErrorCode.TimeoutOrDuplicate:
20
                                return 'The response is no longer valid: either is too old or has been used previously.';
2✔
21

22
                        case ErrorCode.InvalidInputSecret:
23
                        case ErrorCode.MissingInputSecret:
24
                                return 'Invalid module configuration. Please check public-secret keys.';
3✔
25

26
                        case ErrorCode.InvalidKeys:
27
                                return 'Recaptcha token was signed by invalid api key.';
1✔
28

29
                        case ErrorCode.LowScore:
30
                                return 'Low recaptcha score.';
3✔
31

32
                        case ErrorCode.ForbiddenAction:
33
                                return 'Forbidden recaptcha action.';
2✔
34

35
                        case ErrorCode.SiteMismatch:
36
                                return 'The user verification token did not match the provided site key.';
1✔
37

38
                        case ErrorCode.BrowserError:
39
                                return 'Retriable error (such as network failure) occurred on the browser.';
1✔
40

41
                        case ErrorCode.IncorrectCaptchaSol:
42
                                return 'incorrect-captcha-sol';
1✔
43

44
                        case ErrorCode.UnknownError:
45
                        case ErrorCode.BadRequest:
46
                        default:
47
                                return 'Unexpected error. Please submit issue to @nestlab/google-recaptcha.';
6✔
48
                }
49
        }
50

51
        private static getErrorStatus(errorCode: ErrorCode): number {
52
                return errorCode === ErrorCode.InvalidInputResponse ||
31✔
53
                        errorCode === ErrorCode.MissingInputResponse ||
54
                        errorCode === ErrorCode.TimeoutOrDuplicate ||
55
                        errorCode === ErrorCode.ForbiddenAction ||
56
                        errorCode === ErrorCode.SiteMismatch ||
57
                        errorCode === ErrorCode.BrowserError ||
58
                        errorCode === ErrorCode.IncorrectCaptchaSol ||
59
                        errorCode === ErrorCode.LowScore ||
60
                        errorCode === ErrorCode.InvalidKeys
61
                        ? HttpStatus.BAD_REQUEST
62
                        : HttpStatus.INTERNAL_SERVER_ERROR;
63
        }
64
}
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