1

I am doing inline validation for emailId and checking whether emailid already exists or not in database but I am getting this error 406 (Not Acceptable).
For almost every email testcase it is working fine only for one case it is getting failed and i am getting this error in developer tool

GET https://localhost:9002/provisioning-console/json/user/get/user/email-id/fff@dd.cc?ts=1480929984199 406 (Not Acceptable)

user-add-panel.html

<div>
  <div class="col-xs-8 col-sm-8 col-md-9 col-lg-9 controls">
    <input type="text" class="input-xlarge" id="emailId" name="emailId" autofocus="autofocus" ng-model="addUser.email" ng-model-options="{allowInvalid: true}" ng-change="invokeChangeEventEmailId()" ng-blur="invokeOnBlurEventEmail(addUser.email)" ng-pattern="emailpattern"
    placeholder="{{::'placeholder.addUser.emailId'|translate}}" required="true" ng-maxlength="254" />
  </div>

user-add-panel.js

$scope.invokeOnBlurEventEmail = function(email) {

  if (email == null) {
    $scope.emailvalidating = false;
  } else {

    $scope.emailvalidating = true;
  }

  var getRolePromise = userDetails.getUserByEmail(email);
  getRolePromise.then(function(response) {
    $scope.addUserForm.emailId.$setValidity('unique', false);
    $scope.emailvalidating = false;

  }, function(error) {
    $scope.addUserForm.emailId.$setValidity('unique', true);

    if (error.errorCode === 'error.invalid.email') {
      $scope.emailvalidating = false;
    } else {
      toasty.serviceError(error);
      $scope.emailvalidating = false;
    }
  });
}

This is my service which is calling the API

user-state.js

getUserByEmail: function(emailId) {

  var defer = $q.defer();
  restClientTemplate.execute({
    method: 'GET',
    url: 'json/user/get/user/email-id/' + emailId,

  }).then(function(response) {

    defer.resolve(response.results);
  }, function(response) {
    defer.reject(response);

  });
  return defer.promise;
}

enter image description here

Kevin Kloet
  • 1,086
  • 1
  • 11
  • 21
Priyanka Taneja
  • 515
  • 1
  • 5
  • 21
  • Might be helpful: [http://stackoverflow.com/questions/14251851/what-is-406-not-acceptable-response-in-http](http://stackoverflow.com/questions/14251851/what-is-406-not-acceptable-response-in-http) – Rohit Dec 05 '16 at 11:01
  • i tried still getting same error any other suggestion – Priyanka Taneja Dec 08 '16 at 07:09
  • _For almost every email testcase it is working fine only for one case it is getting failed_ **Can you let me know in which case?** – Rohit Dec 08 '16 at 08:08
  • when i am adding .cc at the end for example tanejapriyanka42@gmail.cc then spinner is keep on rotating and m getting 406 error – Priyanka Taneja Dec 08 '16 at 10:22
  • I am using this regex /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; its working fine for all other testcases except .cc at the end – Priyanka Taneja Dec 08 '16 at 10:27
  • Try this: ^([a-zA-Z0-9_\-\.\+]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$ – Rohit Dec 08 '16 at 10:46
  • Failed to load resource: the server responded with a status of 406 (Not Acceptable) still the same issue. – Priyanka Taneja Dec 08 '16 at 12:11
  • 1
    Instead of @PAthVariale i tried Request PAram its working fine now. Thanks.. – Priyanka Taneja Dec 09 '16 at 08:54

2 Answers2

0

Try URI encoding the email.

url:'json/user/get/user/email-id/'+ encodeURIComponent(emailId),
0

.cc might have special significance in URI pattern.Solution

  1. if using @PathVariable specify the acceptable regex for email
  2. easy way is to use @ReqeustParam
vikash vik
  • 686
  • 5
  • 10