[Groonga-commit] groonga/gcs [master] Raise "ResourceNotFound" error for DefineIndexField with not-existing domain

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Nov 15 18:17:18 JST 2012


YUKI Hiroshi	2012-11-15 18:17:18 +0900 (Thu, 15 Nov 2012)

  New Revision: 506846269169a0a8c09b71cade745d51b909bc4d
  https://github.com/groonga/gcs/commit/506846269169a0a8c09b71cade745d51b909bc4d

  Log:
    Raise "ResourceNotFound" error for DefineIndexField with not-existing domain

  Added files:
    lib/errors.js
  Modified files:
    lib/api/2011-02-01/configuration.js
    lib/database/domain.js
    lib/database/index-field.js

  Modified: lib/api/2011-02-01/configuration.js (+7 -4)
===================================================================
--- lib/api/2011-02-01/configuration.js    2012-11-15 18:06:41 +0900 (cde5719)
+++ lib/api/2011-02-01/configuration.js    2012-11-15 18:17:18 +0900 (ffea01e)
@@ -5,6 +5,7 @@ var dateFormat = require('dateformat');
 var xmlbuilder = require('../../xmlbuilder');
 var ipv4 = require('../../ipv4');
 var logger = require('../../logger');
+var errors = require('../../errors');
 var uuid = require('node-uuid');
 
 exports.version = path.basename(__dirname);
@@ -13,7 +14,7 @@ function handleDomanValidationError(process, variables) {
   try {
     return process();
   } catch(error) {
-    if (error.isValidationError) {
+    if (errors.ValidationError.isValidationError(error)) {
       variables = variables || {
                     NAME_FIELD: 'domainName'
                   };
@@ -27,7 +28,7 @@ function handleIndexFieldValidationError(process, variables) {
   try {
     return process();
   } catch(error) {
-    if (error.isValidationError) {
+    if (errors.ValidationError.isValidationError(error)) {
       variables = variables || {
                     NAME_FIELD: 'indexField.indexFieldName',
                     TYPE_FIELD: 'indexField.indexFieldType'
@@ -293,6 +294,8 @@ handlers.DefineIndexField = function(context, request, response, config) {
   var domain = handleDomanValidationError(function() {
         return new Domain(request.query.DomainName || '', context);
       });
+  if (!domain.exists())
+    throw new errors.NotFoundError('Domain not found: ' + domain.name);
 
   var createdAt = new Date();
   var fieldName = request.query['IndexField.IndexFieldName'] || '';
@@ -557,8 +560,8 @@ exports.createHandler = function(context, config) {
     } catch (error) {
       logger.error(error);
       var body, code;
-      if (error.isValidationError) {
-        body = createSenderErrorResponse('ValidationError', error, request.id);
+      if (error.isSenderError) {
+        body = createSenderErrorResponse(error.code, error, request.id);
         code = 400;
       } else {
         body= createCommonErrorResponse('InternalFailure', error, request.id);

  Modified: lib/database/domain.js (+2 -3)
===================================================================
--- lib/database/domain.js    2012-11-15 18:06:41 +0900 (e63f7dc)
+++ lib/database/domain.js    2012-11-15 18:17:18 +0900 (be3ce11)
@@ -8,6 +8,7 @@
 
 var nativeNroonga = require('nroonga');
 var nroonga = require('../wrapped-nroonga');
+var errors = require('../errors');
 var IndexField = require('./index-field').IndexField;
 
 var MINIMUM_NAME_LENGTH =
@@ -91,9 +92,7 @@ function assertValidDomainName(domain) {
     var prefix = errors.length > 1 ? 
                    errors.length + ' validation errors detected: ' :
                    '1 validation error detected: ';
-    var error = new Error(prefix + errors.join('; '));
-    error.isValidationError = true;
-    throw error;
+    throw new errors.ValidationError(prefix + errors.join('; '));
   }
 }
 

  Modified: lib/database/index-field.js (+3 -6)
===================================================================
--- lib/database/index-field.js    2012-11-15 18:06:41 +0900 (5e5f8c3)
+++ lib/database/index-field.js    2012-11-15 18:17:18 +0900 (3a200f5)
@@ -1,4 +1,5 @@
 var nroonga = require('../wrapped-nroonga');
+var errors = require('../errors');
 
 var MINIMUM_NAME_LENGTH =
       exports.MINIMUM_NAME_LENGTH =
@@ -81,9 +82,7 @@ function assertValidFieldName(field) {
     var prefix = errors.length > 1 ? 
                    errors.length + ' validation errors detected: ' :
                    '1 validation error detected: ';
-    var error = new Error(prefix + errors.join('; '));
-    error.isValidationError = true;
-    throw error;
+    throw new errors.ValidationError(prefix + errors.join('; '));
   }
 }
 
@@ -105,9 +104,7 @@ function assertValidFieldType(type) {
     var prefix = errors.length > 1 ? 
                    errors.length + ' validation errors detected: ' :
                    '1 validation error detected: ';
-    var error = new Error(prefix + errors.join('; '));
-    error.isValidationError = true;
-    throw error;
+    throw new errors.ValidationError(prefix + errors.join('; '));
   }
 }
 

  Added: lib/errors.js (+28 -0) 100644
===================================================================
--- /dev/null
+++ lib/errors.js    2012-11-15 18:17:18 +0900 (c1846c2)
@@ -0,0 +1,28 @@
+function ValidationError(message) {
+  var error = new Error(message);
+  error.isValidationError = true;
+  error.isSenderError = true;
+  error.code = 'ValidationError';
+  return error;
+}
+
+ValidationError.isValidationError = function(error) {
+  return !!error.isValidationError;
+};
+
+exports.ValidationError = ValidationError;
+
+
+function NotFoundError(message) {
+  var error = new Error(message);
+  error.isNotFoundError = true;
+  error.isSenderError = true;
+  error.code = 'ResourceNotFound';
+  return error;
+}
+
+NotFoundError.isNotFoundError = function(error) {
+  return !!error.isNotFoundError;
+};
+
+exports.NotFoundError = NotFoundError;
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index