mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 07:04:53 +09:00
Don't log print permission denied stack traces
Use PermissionError to signal when permission is denied for an action and prevent them being logged as stack traces in the master log.
This commit is contained in:
1 parent
7ecac539f9
commit
bfea6cb28e
2 files changed
+17
-2
No files matched your search
@@ -16,6 +16,16 @@ class CommandError extends Error { }
|
||||
*/
|
||||
class RequestError extends Error { }
|
||||
|
||||
/**
|
||||
* Thrown when a permission check fails.
|
||||
*
|
||||
* Is a subclass of RequestError to prevent logging stack traces when
|
||||
* requests fail due to permission denied.
|
||||
*
|
||||
* @static
|
||||
*/
|
||||
class PermissionError extends RequestError { }
|
||||
|
||||
/**
|
||||
* Signal for messages that fail validation
|
||||
* @static
|
||||
@@ -66,6 +76,7 @@ class PluginError extends Error {
|
||||
module.exports = {
|
||||
CommandError,
|
||||
RequestError,
|
||||
PermissionError,
|
||||
InvalidMessage,
|
||||
SessionLost,
|
||||
AuthenticationFailed,
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
"use strict";
|
||||
const jwt = require("jsonwebtoken");
|
||||
|
||||
const libErrors = require("./errors");
|
||||
|
||||
|
||||
/**
|
||||
* Represents a permission that can be granted
|
||||
* @static
|
||||
@@ -254,7 +257,8 @@ class User {
|
||||
* "Permission denied" error is thrown.
|
||||
*
|
||||
* @param {string} permission - The permission to check for.
|
||||
* @throws {Error} if the user does noh have the given permission.
|
||||
* @throws {Error} If the given permission does not exist.
|
||||
* @throws {module:lib/errors.PermissionError} if the user does noh have the given permission.
|
||||
*/
|
||||
checkPermission(permission) {
|
||||
if (!permissions.has(permission)) {
|
||||
@@ -267,7 +271,7 @@ class User {
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error("Permission denied");
|
||||
throw new libErrors.PermissionError("Permission denied");
|
||||
}
|
||||
|
||||
notifyJoin(instance_id) {
|
||||
|
||||
Reference in new issue
Block a user