Browse Source

fix(core): Use correct error type for email address conflict

Closes #299
Michael Bromley 5 years ago
parent
commit
0ba66cb23b

+ 1 - 0
packages/core/src/i18n/messages/en.json

@@ -25,6 +25,7 @@
     "create-fulfillment-orders-must-be-settled": "One or more OrderItems belong to an Order which is in an invalid state",
     "create-fulfillment-nothing-to-fulfill": "Nothing to fulfill",
     "default-channel-not-found":  "Default channel not found",
+    "email-address-must-be-unique": "The email address must be unique",
     "email-address-not-available": "This email address is not available",
     "email-address-not-verified": "Please verify this email address before logging in",
     "entity-has-no-translation-in-language": "Translatable entity '{ entityName }' has not been translated into the requested language ({ languageCode })",

+ 2 - 7
packages/core/src/service/services/customer.service.ts

@@ -13,12 +13,7 @@ import { ID, PaginatedList } from '@vendure/common/lib/shared-types';
 import { Connection } from 'typeorm';
 
 import { RequestContext } from '../../api/common/request-context';
-import {
-    EntityNotFoundError,
-    IllegalOperationError,
-    InternalServerError,
-    UserInputError,
-} from '../../common/error/errors';
+import { EntityNotFoundError, IllegalOperationError, UserInputError } from '../../common/error/errors';
 import { ListQueryOptions } from '../../common/types/common-types';
 import { assertFound, idsAreEqual, normalizeEmailAddress } from '../../common/utils';
 import { ConfigService } from '../../config/config.service';
@@ -96,7 +91,7 @@ export class CustomerService {
         });
 
         if (existing) {
-            throw new InternalServerError(`error.email-address-must-be-unique`);
+            throw new UserInputError(`error.email-address-must-be-unique`);
         }
         customer.user = await this.userService.createCustomerUser(input.emailAddress, password);