feat: Add option logLevels.signupUsernameTaken to change log level of username already exists sign-up rejection (#9962)
This commit is contained in:
@@ -1481,6 +1481,12 @@ module.exports.LogLevels = {
|
||||
'Log level used by the Cloud Code Functions on success. Default is `info`. See [LogLevel](LogLevel.html) for available values.',
|
||||
default: 'info',
|
||||
},
|
||||
signupUsernameTaken: {
|
||||
env: 'PARSE_SERVER_LOG_LEVELS_SIGNUP_USERNAME_TAKEN',
|
||||
help:
|
||||
'Log level used when a sign-up fails because the username already exists. Default is `info`. See [LogLevel](LogLevel.html) for available values.',
|
||||
default: 'info',
|
||||
},
|
||||
triggerAfter: {
|
||||
env: 'PARSE_SERVER_LOG_LEVELS_TRIGGER_AFTER',
|
||||
help:
|
||||
|
||||
@@ -324,6 +324,7 @@
|
||||
* @interface LogLevels
|
||||
* @property {String} cloudFunctionError Log level used by the Cloud Code Functions on error. Default is `error`. See [LogLevel](LogLevel.html) for available values.
|
||||
* @property {String} cloudFunctionSuccess Log level used by the Cloud Code Functions on success. Default is `info`. See [LogLevel](LogLevel.html) for available values.
|
||||
* @property {String} signupUsernameTaken Log level used when a sign-up fails because the username already exists. Default is `info`. See [LogLevel](LogLevel.html) for available values.
|
||||
* @property {String} triggerAfter Log level used by the Cloud Code Triggers `afterSave`, `afterDelete`, `afterFind`, `afterLogout`. Default is `info`. See [LogLevel](LogLevel.html) for available values.
|
||||
* @property {String} triggerBeforeError Log level used by the Cloud Code Triggers `beforeSave`, `beforeDelete`, `beforeFind`, `beforeLogin` on error. Default is `error`. See [LogLevel](LogLevel.html) for available values.
|
||||
* @property {String} triggerBeforeSuccess Log level used by the Cloud Code Triggers `beforeSave`, `beforeDelete`, `beforeFind`, `beforeLogin` on success. Default is `info`. See [LogLevel](LogLevel.html) for available values.
|
||||
|
||||
@@ -786,4 +786,8 @@ export interface LogLevels {
|
||||
:DEFAULT: error
|
||||
*/
|
||||
cloudFunctionError: ?string;
|
||||
/* Log level used when a sign-up fails because the username already exists. Default is `info`. See [LogLevel](LogLevel.html) for available values.
|
||||
:DEFAULT: info
|
||||
*/
|
||||
signupUsernameTaken: ?string;
|
||||
}
|
||||
|
||||
@@ -466,6 +466,8 @@ export function handleParseErrors(err, req, res, next) {
|
||||
if (req.config && req.config.enableExpressErrorHandler) {
|
||||
return next(err);
|
||||
}
|
||||
const signupUsernameTakenLevel =
|
||||
req.config?.logLevels?.signupUsernameTaken || 'info';
|
||||
let httpStatus;
|
||||
// TODO: fill out this mapping
|
||||
switch (err.code) {
|
||||
@@ -480,7 +482,17 @@ export function handleParseErrors(err, req, res, next) {
|
||||
}
|
||||
res.status(httpStatus);
|
||||
res.json({ code: err.code, error: err.message });
|
||||
log.error('Parse error: ', err);
|
||||
if (err.code === Parse.Error.USERNAME_TAKEN) {
|
||||
if (signupUsernameTakenLevel !== 'silent') {
|
||||
const loggerMethod =
|
||||
typeof log[signupUsernameTakenLevel] === 'function'
|
||||
? log[signupUsernameTakenLevel].bind(log)
|
||||
: log.error.bind(log);
|
||||
loggerMethod('Parse error: ', err);
|
||||
}
|
||||
} else {
|
||||
log.error('Parse error: ', err);
|
||||
}
|
||||
} else if (err.status && err.message) {
|
||||
res.status(err.status);
|
||||
res.json({ error: err.message });
|
||||
|
||||
Reference in New Issue
Block a user