File tree Expand file tree Collapse file tree
packages/asset-uploader/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { describe , expect , test } from "vitest" ;
2+ import { MaxAssetsPerProjectError } from "@webstudio-is/asset-uploader/index.server" ;
3+
4+ describe ( "MaxAssetsPerProjectError" , ( ) => {
5+ test ( "can be classified by type" , ( ) => {
6+ expect ( new MaxAssetsPerProjectError ( 100 ) ) . toBeInstanceOf (
7+ MaxAssetsPerProjectError
8+ ) ;
9+ } ) ;
10+ } ) ;
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import type { Asset } from "@webstudio-is/sdk";
66import {
77 loadAssetsByProject ,
88 createUploadName ,
9+ MaxAssetsPerProjectError ,
910} from "@webstudio-is/asset-uploader/index.server" ;
1011import { createContext } from "~/shared/context.server" ;
1112import { preventCrossOriginCookie } from "~/services/no-cross-origin-cookie" ;
@@ -61,10 +62,16 @@ export const action = async (props: ActionFunctionArgs) => {
6162 } ;
6263 }
6364 } catch ( error ) {
64- console . error ( error ) ;
65+ const parsedError = parseError ( error ) ;
66+
67+ if ( error instanceof MaxAssetsPerProjectError ) {
68+ console . info ( error ) ;
69+ } else {
70+ console . error ( error ) ;
71+ }
6572
6673 return {
67- errors : parseError ( error ) . message ,
74+ errors : parsedError . message ,
6875 } ;
6976 }
7077} ;
Original file line number Diff line number Diff line change @@ -11,9 +11,3 @@ export const MaxSize: z.ZodEffects<
1111 . default ( MAX_UPLOAD_SIZE )
1212 // user inputs the max value in mb and we transform it to bytes
1313 . transform ( toBytes ) ;
14-
15- export const MaxAssets : z . ZodEffects <
16- z . ZodDefault < z . ZodString > ,
17- number ,
18- string | undefined
19- > = z . string ( ) . default ( "100" ) . transform ( Number . parseFloat ) ;
Original file line number Diff line number Diff line change @@ -17,6 +17,15 @@ type UploadData = {
1717 maxAssetsPerProject : number ;
1818} ;
1919
20+ export class MaxAssetsPerProjectError extends Error {
21+ constructor ( maxAssetsPerProject : number ) {
22+ super (
23+ `The maximum number of assets per project is ${ maxAssetsPerProject } .`
24+ ) ;
25+ this . name = "MaxAssetsPerProjectError" ;
26+ }
27+ }
28+
2029const UPLOADING_STALE_TIMEOUT = 1000 * 60 * 30 ; // 30 minutes
2130
2231export const createUploadName = async (
@@ -65,9 +74,7 @@ export const createUploadName = async (
6574 * it's probable that the user can exceed the limit a little bit.
6675 * So it can be a little bit strange that the limit is 5 but the user already has 7.
6776 **/
68- throw new Error (
69- `The maximum number of assets per project is ${ maxAssetsPerProject } .`
70- ) ;
77+ throw new MaxAssetsPerProjectError ( maxAssetsPerProject ) ;
7178 }
7279
7380 /**
You can’t perform that action at this time.
0 commit comments