Search code examples
javascriptxamarinazure-mobile-servicesinternal-server-errorcustom-authentication

Error in script '/api/register.js'. Error: Error loading the api


I have followed this tutorial in custom authentication using Azure Mobile Services. My service was up and running for a while but I started actually implementing a client side data repository now.

So while I was testing from an iOS client the custom API register.js I couldn't make it to work with the logs appearing the following error.

Server Logs Error

I don't get it since the register.js is in place. Also I use GIT source control to edit the custom API files remotely sometimes.

My Xamarin client code is the following.

        public async Task<string> RegisterUser (string email, string password)
        {
            try
            {
                JObject registerJObject = new JObject();
                registerJObject.Add("email", email);
                registerJObject.Add("password", password);
                JToken response = await MobileService.InvokeApiAsync("register", registerJObject, HttpMethod.Post, null);
                string status = response["Status"].Value<string>();
                if (status == FAIL)
                {
                    // failed, do something
                }
                else if (status == SUCCESS)
                {
                    string token = response["token"].Value<string>();
                    // do something with the token
                }
                return status;

            }
            catch (MobileServiceInvalidOperationException ex)
            {
                throw;
            }
        }

Still working in reporting the error etc but you get the problem, it's an internal 500 error and I can see the logs in the above screenshot.


Solution

  • The error: "Error in script ... Error loading the api" typically indicates that there is a syntax issue that needs to be fixed inside the the specified javascript file.