mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
* Limit users * Add defaults * Allow specifying of reason for limit exceeded error * Update config options doc * Make existing tests pass * Update extensions limit error * Update usage of regular expression Co-authored-by: Brainslug <br41nslug@users.noreply.github.com> * Rename typo Co-authored-by: Brainslug <br41nslug@users.noreply.github.com> * Rename files Co-authored-by: Brainslug <br41nslug@users.noreply.github.com> * Use first() and remove redundant += * Fix incorrect api access count * Rework to account for passing of unchanged access values * Fix increased counts in updateMany * Consistent error message * Simplify unnecessary find * Add tests * Rename UserCount to AccessTypeCount * renamed env var * prettier * Add changeset * fix limit checking for batch and status updates * test and prettier * removed obsolete check * updated error * fixed error usage in extenions service * Use randomUUID from '@directus/random' * Fix payload check in updateMany * implemented RolesService.updateBatch from its parent * resolved unit test error * updated type * fixed existing role query * Temporary activation of blackbox tests * Move to separate fn, to make skippable for non-existent role * Revert "Temporary activation of blackbox tests" This reverts commit4c4ac846d6. * Revert "Move to separate fn, to make skippable for non-existent role" This reverts commit1d90a82e39. * Add user limits - extension (#22642) * adressing existing users issue * migrated changes from pascal * only check the role for active users * only count active users * updated incorrect if * default to count zero * Undid abstraction to separate function * fixed updating through user counting error * prettier * simplified fallback query * prettier * Added try catch to be safee * updated db mocking for tests * removed extra check to satisfy implementation tests --------- Co-authored-by: Brainslug <br41nslug@users.noreply.github.com> Co-authored-by: Brainslug <tim@brainslug.nl> Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
@directus/errors
Utility functions to help creating and checking against Directus errors.
Installation
pnpm add @directus/errors
Usage
Creating a new Error class
createError(code: string, message: string | (T) => string, status = 500): DirectusErrorConstructor<T>
import { createError } from '@directus/errors';
const ForbiddenError = createError('FORBIDDEN', "You don't have permissions to see this.", 403);
throw new ForbiddenError();
You can configure additional extensions for the error class which should be communicated to the end user:
import { createError } from '@directus/errors';
interface ForbiddenErrorExtensions {
collection: string;
field: string;
}
const ForbiddenError = createError<ForbiddenErrorExtensions>(
'FORBIDDEN',
"You don't have permissions to see this.",
403,
);
throw new ForbiddenError({
collection: 'articles',
field: 'title',
});
You can then also use those extensions to generate out the error message:
import { createError } from '@directus/errors';
interface ForbiddenErrorExtensions {
collection: string;
field: string;
}
const messageConstructor = (extensions: ForbiddenErrorExtensions) =>
`You don't have permissions to see "${extensions.field}" in "${extensions.collection}".`;
const ForbiddenError = createError<ForbiddenErrorExtensions>('FORBIDDEN', messageConstructor, 403);
throw new ForbiddenError({
collection: 'articles',
field: 'title',
});
Checking if a given param is a valid DirectusError instance
import { isDirectusError, createError } from '@directus/errors';
const ForbiddenError = createError('FORBIDDEN', "You don't have permissions to see this.", 403);
isDirectusError(new ForbiddenError()); // true
isDirectusError(new Error()); // false