Просмотр исходного кода

[AuthorizationManager] use a new NotAuthorizedError

Jakob Ackermann 6 лет назад
Родитель
Сommit
a8c51de510
2 измененных файлов с 11 добавлено и 2 удалено
  1. 4 2
      services/real-time/app/js/AuthorizationManager.js
  2. 7 0
      services/real-time/app/js/Errors.js

+ 4 - 2
services/real-time/app/js/AuthorizationManager.js

@@ -1,6 +1,8 @@
 /* eslint-disable
 /* eslint-disable
     camelcase,
     camelcase,
 */
 */
+const { NotAuthorizedError } = require('./Errors')
+
 let AuthorizationManager
 let AuthorizationManager
 module.exports = AuthorizationManager = {
 module.exports = AuthorizationManager = {
   assertClientCanViewProject(client, callback) {
   assertClientCanViewProject(client, callback) {
@@ -23,7 +25,7 @@ module.exports = AuthorizationManager = {
     if (allowedLevels.includes(client.ol_context.privilege_level)) {
     if (allowedLevels.includes(client.ol_context.privilege_level)) {
       callback(null)
       callback(null)
     } else {
     } else {
-      callback(new Error('not authorized'))
+      callback(new NotAuthorizedError())
     }
     }
   },
   },
 
 
@@ -49,7 +51,7 @@ module.exports = AuthorizationManager = {
     if (client.ol_context[`doc:${doc_id}`] === 'allowed') {
     if (client.ol_context[`doc:${doc_id}`] === 'allowed') {
       callback(null)
       callback(null)
     } else {
     } else {
-      callback(new Error('not authorized'))
+      callback(new NotAuthorizedError())
     }
     }
   },
   },
 
 

+ 7 - 0
services/real-time/app/js/Errors.js

@@ -21,6 +21,12 @@ class MissingSessionError extends OError {
   }
   }
 }
 }
 
 
+class NotAuthorizedError extends OError {
+  constructor() {
+    super('not authorized')
+  }
+}
+
 class NullBytesInOpError extends OError {
 class NullBytesInOpError extends OError {
   constructor(jsonChange) {
   constructor(jsonChange) {
     super('null bytes found in op', { jsonChange })
     super('null bytes found in op', { jsonChange })
@@ -37,6 +43,7 @@ module.exports = {
   CodedError,
   CodedError,
   DataTooLargeToParseError,
   DataTooLargeToParseError,
   MissingSessionError,
   MissingSessionError,
+  NotAuthorizedError,
   NullBytesInOpError,
   NullBytesInOpError,
   UpdateTooLargeError
   UpdateTooLargeError
 }
 }