Skip to content

Commit

Permalink
Merge pull request #41 from chvarkov/develop
Browse files Browse the repository at this point in the history
Handled invalid api key error.
  • Loading branch information
chvarkov authored Apr 17, 2021
2 parents 4ea64b9 + ea3b72e commit 97b2b43
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestlab/google-recaptcha",
"version": "2.0.1",
"version": "2.0.2",
"description": "Google recaptcha module for NestJS.",
"keywords": [
"nest",
Expand Down
1 change: 1 addition & 0 deletions src/enums/error-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export enum ErrorCode {
UnknownError = 'unknown-error',
ForbiddenAction = 'forbidden-action',
LowScore = 'low-score',
InvalidKeys = 'invalid-keys',
}
10 changes: 7 additions & 3 deletions src/exceptions/google-recaptcha.exception.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpException, HttpStatus } from '@nestjs/common';
import { ErrorCode } from '../enums/error-code';
import {HttpException, HttpStatus} from '@nestjs/common';
import {ErrorCode} from '../enums/error-code';

export class GoogleRecaptchaException extends HttpException {

Expand All @@ -21,6 +21,9 @@ export class GoogleRecaptchaException extends HttpException {
case ErrorCode.MissingInputSecret:
return 'Invalid module configuration. Please check public-secret keys.';

case ErrorCode.InvalidKeys:
return 'Recaptcha token was signed by invalid api key.';

case ErrorCode.LowScore:
return 'Low recaptcha score.'

Expand All @@ -39,7 +42,8 @@ export class GoogleRecaptchaException extends HttpException {
errorCode === ErrorCode.MissingInputResponse ||
errorCode === ErrorCode.TimeoutOrDuplicate ||
errorCode === ErrorCode.ForbiddenAction ||
errorCode === ErrorCode.LowScore
errorCode === ErrorCode.LowScore ||
errorCode === ErrorCode.InvalidKeys
? HttpStatus.BAD_REQUEST
: HttpStatus.INTERNAL_SERVER_ERROR;
}
Expand Down

0 comments on commit 97b2b43

Please sign in to comment.