mirror of
https://github.com/unraid/api.git
synced 2025-12-31 13:39:52 -06:00
fix: clearer error messaging
This commit is contained in:
@@ -154,7 +154,7 @@ describe('ApiKeyService', () => {
|
||||
const saveSpy = vi.spyOn(apiKeyService, 'saveApiKey');
|
||||
|
||||
await expect(apiKeyService.create('', 'desc', [Role.GUEST])).rejects.toThrow(
|
||||
'API key name must be alphanumeric + spaces'
|
||||
'API key name must contain only letters, numbers, and spaces (Unicode letters are supported)'
|
||||
);
|
||||
|
||||
await expect(apiKeyService.create('name', 'desc', [])).rejects.toThrow(
|
||||
|
||||
@@ -3,15 +3,23 @@ import crypto from 'crypto';
|
||||
import { readdir, readFile, writeFile } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
|
||||
|
||||
|
||||
import { ensureDir } from 'fs-extra';
|
||||
import { GraphQLError } from 'graphql';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { ZodError } from 'zod';
|
||||
|
||||
|
||||
|
||||
import { ApiKeySchema, ApiKeyWithSecretSchema } from '@app/graphql/generated/api/operations';
|
||||
import { ApiKey, ApiKeyWithSecret, Role, UserAccount } from '@app/graphql/generated/api/types';
|
||||
import { getters } from '@app/store';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class ApiKeyService implements OnModuleInit {
|
||||
private readonly logger = new Logger(ApiKeyService.name);
|
||||
@@ -47,7 +55,9 @@ export class ApiKeyService implements OnModuleInit {
|
||||
if (/^[\p{L}\p{N} ]+$/u.test(name)) {
|
||||
return name;
|
||||
} else {
|
||||
throw new GraphQLError('API key name must be alphanumeric + spaces');
|
||||
throw new GraphQLError(
|
||||
'API key name must contain only letters, numbers, and spaces (Unicode letters are supported)'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,4 +308,4 @@ export class ApiKeyService implements OnModuleInit {
|
||||
keyFile: this.keyFile,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user