mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-22 03:05:19 -04:00
config: Improve error messages
Add labels to most Joi objects Convert all auth variable insert names to upper case to prevent inconsistent naming of the variables Rewrite auth errors to correctly point out the problematic variable Add tests for the config utils functions Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
5cb1f29a2c
commit
454a883f17
8 changed files with 372 additions and 168 deletions
|
@ -7,6 +7,7 @@
|
|||
import * as Joi from 'joi';
|
||||
import { DatabaseDialect } from './database-dialect.enum';
|
||||
import { registerAs } from '@nestjs/config';
|
||||
import { buildErrorMessage } from './utils';
|
||||
|
||||
export interface DatabaseConfig {
|
||||
username: string;
|
||||
|
@ -23,33 +24,35 @@ const databaseSchema = Joi.object({
|
|||
is: Joi.invalid(DatabaseDialect.SQLITE),
|
||||
then: Joi.string(),
|
||||
otherwise: Joi.optional(),
|
||||
}),
|
||||
}).label('HD_DATABASE_USER'),
|
||||
password: Joi.when('dialect', {
|
||||
is: Joi.invalid(DatabaseDialect.SQLITE),
|
||||
then: Joi.string(),
|
||||
otherwise: Joi.optional(),
|
||||
}),
|
||||
}).label('HD_DATABASE_PASS'),
|
||||
database: Joi.when('dialect', {
|
||||
is: Joi.invalid(DatabaseDialect.SQLITE),
|
||||
then: Joi.string(),
|
||||
otherwise: Joi.optional(),
|
||||
}),
|
||||
}).label('HD_DATABASE_NAME'),
|
||||
host: Joi.when('dialect', {
|
||||
is: Joi.invalid(DatabaseDialect.SQLITE),
|
||||
then: Joi.string(),
|
||||
otherwise: Joi.optional(),
|
||||
}),
|
||||
}).label('HD_DATABASE_HOST'),
|
||||
port: Joi.when('dialect', {
|
||||
is: Joi.invalid(DatabaseDialect.SQLITE),
|
||||
then: Joi.number(),
|
||||
otherwise: Joi.optional(),
|
||||
}),
|
||||
}).label('HD_DATABASE_PORT'),
|
||||
storage: Joi.when('dialect', {
|
||||
is: Joi.valid(DatabaseDialect.SQLITE),
|
||||
then: Joi.string(),
|
||||
otherwise: Joi.optional(),
|
||||
}),
|
||||
dialect: Joi.string().valid(...Object.values(DatabaseDialect)),
|
||||
}).label('HD_DATABASE_STORAGE'),
|
||||
dialect: Joi.string()
|
||||
.valid(...Object.values(DatabaseDialect))
|
||||
.label('HD_DATABASE_DIALECT'),
|
||||
});
|
||||
|
||||
export default registerAs('databaseConfig', async () => {
|
||||
|
@ -69,7 +72,10 @@ export default registerAs('databaseConfig', async () => {
|
|||
},
|
||||
);
|
||||
if (databaseConfig.error) {
|
||||
throw new Error(databaseConfig.error.toString());
|
||||
const errorMessages = await databaseConfig.error.details.map(
|
||||
(detail) => detail.message,
|
||||
);
|
||||
throw new Error(buildErrorMessage(errorMessages));
|
||||
}
|
||||
return databaseConfig.value;
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue