Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions redisinsight/api/src/constants/error-messages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable max-len */
import { numberWithSpaces } from 'src/utils/base.helper';

export default {
UNAUTHORIZED: 'Authorization failed',
FORBIDDEN: 'Access denied',
Expand Down Expand Up @@ -102,8 +104,10 @@ export default {
`Required ${module} module is not loaded.`,
APP_SETTINGS_NOT_FOUND: () => 'Could not find application settings.',
SERVER_INFO_NOT_FOUND: () => 'Could not find server info.',
INCREASE_MINIMUM_LIMIT: (count: string) =>
`Set MAXSEARCHRESULTS to at least ${count}.`,
INCREASE_MINIMUM_LIMIT: (count?: number) =>
count
? `Set MAXSEARCHRESULTS to at least ${numberWithSpaces(count)}.`
: 'Increase MAXSEARCHRESULTS value to search more.',
INVALID_WINDOW_ID: 'Invalid window id.',
UNDEFINED_WINDOW_ID: 'Undefined window id.',
LIBRARY_NOT_EXIST: 'This library does not exist.',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { isUndefined, toNumber, uniq } from 'lodash';
import {
BadRequestException,
ConflictException,
HttpException,
Injectable,
Logger,
} from '@nestjs/common';
import ERROR_MESSAGES from 'src/constants/error-messages';
import { catchAclError } from 'src/utils';
import { catchRedisSearchError } from 'src/utils';
import { ClientMetadata } from 'src/common/models';
import {
CreateRedisearchIndexDto,
Expand All @@ -17,9 +15,8 @@ import {
SearchRedisearchDto,
} from 'src/modules/browser/redisearch/dto';
import { GetKeysWithDetailsResponse } from 'src/modules/browser/keys/dto';
import { DEFAULT_MATCH, RedisErrorCodes } from 'src/constants';
import { DEFAULT_MATCH } from 'src/constants';
import { plainToInstance } from 'class-transformer';
import { numberWithSpaces } from 'src/utils/base.helper';
import { BrowserHistoryMode, RedisString } from 'src/common/constants';
import { CreateBrowserHistoryDto } from 'src/modules/browser/browser-history/dto';
import { BrowserHistoryService } from 'src/modules/browser/browser-history/browser-history.service';
Expand Down Expand Up @@ -68,7 +65,8 @@ export class RedisearchService {
});
} catch (e) {
this.logger.error('Failed to get redisearch indexes', e, clientMetadata);
throw catchAclError(e);

throw catchRedisSearchError(e);
}
}

Expand Down Expand Up @@ -142,7 +140,8 @@ export class RedisearchService {
return undefined;
} catch (e) {
this.logger.error('Failed to create redisearch index', e, clientMetadata);
throw catchAclError(e);

throw catchRedisSearchError(e);
}
}

Expand Down Expand Up @@ -174,7 +173,8 @@ export class RedisearchService {
return plainToInstance(IndexInfoDto, convertIndexInfoReply(infoReply));
} catch (e) {
this.logger.error('Failed to get index info', e, clientMetadata);
throw catchAclError(e);

throw catchRedisSearchError(e);
}
}

Expand Down Expand Up @@ -264,15 +264,8 @@ export class RedisearchService {
e,
clientMetadata,
);
if (e instanceof HttpException) {
throw e;
}
if (e.message?.includes(RedisErrorCodes.RedisearchLimit)) {
throw new BadRequestException(
ERROR_MESSAGES.INCREASE_MINIMUM_LIMIT(numberWithSpaces(dto.limit)),
);
}
throw catchAclError(e);

throw catchRedisSearchError(e, { searchLimit: dto.limit });
}
}

Expand Down
21 changes: 21 additions & 0 deletions redisinsight/api/src/utils/catch-redis-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,24 @@ export const catchMultiTransactionError = (
if (err) throw err;
});
};

export const catchRedisSearchError = (
error: ReplyError,
options?: { searchLimit?: number },
): HttpException => {
if (error instanceof HttpException) {
throw error;
}

if (error.message?.includes(RedisErrorCodes.RedisearchLimit)) {
throw new BadRequestException(
ERROR_MESSAGES.INCREASE_MINIMUM_LIMIT(options?.searchLimit),
);
}

if (error.message?.includes('Unknown index')) {
throw new NotFoundException(error.message);
}

throw catchAclError(error);
};
Loading