Skip to content

Commit bdc3e47

Browse files
committed
fix: clearer error messaging
1 parent db7b380 commit bdc3e47

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

api/src/unraid-api/auth/api-key.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ describe('ApiKeyService', () => {
154154
const saveSpy = vi.spyOn(apiKeyService, 'saveApiKey');
155155

156156
await expect(apiKeyService.create('', 'desc', [Role.GUEST])).rejects.toThrow(
157-
'API key name must be alphanumeric + spaces'
157+
'API key name must contain only letters, numbers, and spaces (Unicode letters are supported)'
158158
);
159159

160160
await expect(apiKeyService.create('name', 'desc', [])).rejects.toThrow(

api/src/unraid-api/auth/api-key.service.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@ import crypto from 'crypto';
33
import { readdir, readFile, writeFile } from 'fs/promises';
44
import { join } from 'path';
55

6+
7+
68
import { ensureDir } from 'fs-extra';
79
import { GraphQLError } from 'graphql';
810
import { v4 as uuidv4 } from 'uuid';
911
import { ZodError } from 'zod';
1012

13+
14+
1115
import { ApiKeySchema, ApiKeyWithSecretSchema } from '@app/graphql/generated/api/operations';
1216
import { ApiKey, ApiKeyWithSecret, Role, UserAccount } from '@app/graphql/generated/api/types';
1317
import { getters } from '@app/store';
1418

19+
20+
21+
22+
1523
@Injectable()
1624
export class ApiKeyService implements OnModuleInit {
1725
private readonly logger = new Logger(ApiKeyService.name);
@@ -47,7 +55,9 @@ export class ApiKeyService implements OnModuleInit {
4755
if (/^[\p{L}\p{N} ]+$/u.test(name)) {
4856
return name;
4957
} else {
50-
throw new GraphQLError('API key name must be alphanumeric + spaces');
58+
throw new GraphQLError(
59+
'API key name must contain only letters, numbers, and spaces (Unicode letters are supported)'
60+
);
5161
}
5262
}
5363

@@ -298,4 +308,4 @@ export class ApiKeyService implements OnModuleInit {
298308
keyFile: this.keyFile,
299309
};
300310
}
301-
}
311+
}

0 commit comments

Comments
 (0)