amplify-js: unknown error with 200 when sign up user

I’m using the cognito javascript sdk at a lambda function (i fork the library to support for server side) and when i try to sign up new user with email, the user is created fine in the user pool, however in the callback, it return unknown error with status code 200.

{“code”:“UnknownError”,“name”:“UnknownError”,“statusCode”:200,“message”:“200”}

userPool.signUp(username, event.password, attributeList, null, function(err, result){
        if (err) {
            callback(null, {
                statusCode: 400,
                body: JSON.stringify({
                    resultMessage: "UNKNOWN_ERROR",
                    resultDescription: err.message
                })
              });
            return;
        }
        cognitoUser = result.user;

        callback(null, {
            "resultDescription": "SUCCESS",
            "resultMessage": "Successfully registered." ,
            "body": result.user
        });
    });

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 44 (5 by maintainers)

Most upvoted comments

Hey all, I was running into this same issue for the past few days. For me, I was getting the error because I had the “Do you want to remember your user’s devices” set to “Always”. I set it to “No” and that fixed it. I’m wondering if its because this library is meant for the client-side (I’m using this in a lambda) and with that option enabled, the library is trying to use some browser-specific way of determining the device, but that’s just a blind guess.

For me, It’s because I try to sign in with user/password generated from Admin. So, I add newPasswordRequired callback and problem gone.

newPasswordRequired: (userAttributes, requiredAttributes) => {
  delete userAttributes.email_verified;

  cognitoUser.completeNewPasswordChallenge(
    "newPassword",
    userAttributes,
    this
  );
}
`

I’m using amazon-cognito-identity-js version 2.0.1. I needed to add the following to Client.js file of the above package as a workaround to Fetch API error: var fetch = require(‘node-fetch’);

After that, Fetch API error was resolved, but started seeing the ‘UnknownError’ with status code 200 on call cognitoUser.authenticateUser

I get the same error when trying to call cognitoUser.authenticateUser from within AWS Lambda Function (Node.js 4.3 or 6.10) as per Use case 4 in https://github.com/aws/aws-amplify/tree/master/packages/amazon-cognito-identity-js { “code”: “UnknownError”, “name”: “UnknownError”, “statusCode”: 200, “message”: “200” }

Getting same error as few of you had mentioned above during Signup. Although User Registration is successful.

Error - “Unknown error, the response body from fetch is: undefined”

Tried few suggestions but didn’t get rid of this error.

Thanks, Tanveer

make this changes on your project: yarn add node-fetch

and then: global.fetch = require(‘node-fetch’)

before using AWS Cognito.

I think the reason that this is fixed when you turn off remember devices is that it will stop trying to interrogate the device about its nature. It will look at window.navigator (which in a node environment’s equivalent global.navigator will be undefined).

It can be tricked fairly easily by doing this at the start of the node application.

global.navigator = {};

I agree with @sballa12 that enhancing the library to not swallow this error would be the best solution (alongside doc enhancement)

@mlabieniec Although clear documentation in troubleshooting section would definitely help, I still feel that it would be good to enhance the library code to handle this error gracefully.

Hey @mlabieniec , I did some more looking into this for my case. I added in

    onFailure: function (err) {
      console.log(new Error().stack);
    },

To get the stacktrace, and it was as simple as I hadn’t implemented the newPasswordRequired function in the callback. The output was TypeError: callback.newPasswordRequired is not a function. Maybe this catch in Client.js could be instead refactored as function(err) {...} and return some context with var Error?

I’m getting the same error as @medarz is. My callback in userPool.signUp is getting called twice… The first is successful. The second one has the error.

Hey, @wcken84 , for this catch, try doing what I’ve done above with changing it to

    }).catch(function (err) {
      // Taken from aws-sdk-js/lib/protocol/json.js
      console.log(`error: ${err}`);

If you’re lucky (like I was), it may show you the method you need to implement in your callback Don’t forget to change it back after you’ve finished debugging 😃

Hey @mlabieniec , I did some more looking into this for my case. I added in

    onFailure: function (err) {
      console.log(new Error().stack);
    },

To get the stacktrace, and it was as simple as I hadn’t implemented the newPasswordRequired function in the callback. The output was TypeError: callback.newPasswordRequired is not a function. Maybe this catch in Client.js could be instead refactored as function(err) {...} and return some context with var Error?

Thank you! After implementing newPasswordRequired too, it started working.

Anyone working on this issue ? I have tried the provided solutions, but still getting the error message. As @nikhilsinha mentioned the function gets called twice and the second one fails.

I have narrowed down the problem to an async call via Promise - when not using Promise everything works fine

//return new Promise(function(resolve, reject){
    userPool.signUp(login, password, attributeList, null, function(err, result){
        if (err) {
          console.log(`Problem creating user ${JSON.stringify(err)}`);
          //reject(err);
        }
        else{
          console.log(`User successfully created ${JSON.stringify(result)}`)
          cognitoUser = result.user;
          //reslove(cognitoUser);
        }

    });
  //});

I am having the same issue as I turned on device registration to Always. However, I can’t turn it off as we need to enable this feature. Please let me know if there is any work around.

Same here. Although Sign up was successful, and also received response like - {“CodeDeliveryDetails”:{“AttributeName”:“email”,“DeliveryMedium”:“EMAIL”,“Destination”:“s***@y***.com”},“UserConfirmed”:false,“UserSub”:“*****************”}, but inside the function it’s throwing error - {code: “UnknownError”, message: “Unknown error, the response body from fetch is: undefined”}.

Using inside ReactJS with amazon-cognito-identity-js v2.0.21

Same here. Registration is successful for the user, but signUp is returning “Unknown error, the response body from fetch is: undefined”. I’m doing this request from the browser.

@scvnathan solution of turning off ‘Remember user’s device’ in cognito user pool fixed the issue with cognitoUser.authenticateUser

Fixed it…

I’m new to NodeJS, so not sure if this is how it works, but there was an error in my onSuccess function, which then caused the script to fall into onFailure and return this un-useful error message.

I was trying to also use ‘aws-sdk’, but hadn’t installed or imported it. Not sure if it’s the same issue for you @wcken84, but all I did was install+import, and it worked.

Same error @wcken84 , but on sign in. Very vague and difficult to determine what is wrong…

@MacMcIrish thank you for that!

@sballa12 have you tried this to see if it returns similarly ?

We are checking with the service teams to see if we can identify anything in the logs. Btw how are you dealing with the fetch requests in node? Re: #403