laravelhttp-status-code-409

409 conflict error only on wifi only during register


I am trying to register the user. But the registration process is working fine on mobile data but it is returning 409 error on wifi network. I am unknown about this problem. The postman is also returning the 409 conflict.
I am getting this response in android app:

E/Volley: [88456] BasicNetwork.performRequest: Unexpected response code 409 for https://aayocab.com/api/provider/register/

enter image description here

It was working fine during the initial phase of project. But it starts returning the conflict now and I am in dilema. I have implemented as follows:

The laravel code to register:

  public function register(Request $request)
{
    $this->validate($request, [
            'device_id' => 'required',
            'device_type' => 'required|in:android,ios',
            'device_token' => 'required',
            'first_name' => 'required|max:255',
            'last_name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:providers',
            'mobile' => 'required',
            'password' => 'required|min:6|confirmed',
        ]);
    try{
        $Provider = $request->all();
        $Provider['password'] = bcrypt($request->password);
        $providerCode = 'p'.mt_rand(100, 999). mt_rand(100, 999);
        $Provider['provider_code'] = $providerCode;
        $Provider = Provider::create($Provider);

        if(Setting::get('demo_mode', 0) == 1) {
            $Provider->update(['status' => 'approved']);
            ProviderService::create([
                'provider_id' => $Provider->id,
                'service_type_id' => '1',
                'status' => 'active',
                'service_number' => '4pp03ets',
                'service_model' => 'Audi R8',
            ]);
        }
        ProviderDevice::create([
                'provider_id' => $Provider->id,
                'udid' => $request->device_id,
                'token' => $request->device_token,
                'type' => $request->device_type,
            ]);
        return $Provider;
    } catch (Exception $e) {
         return response()->json(['error' => trans('api.something_went_wrong')], 500);
    }     
}

I have parsed the data as follows in andorid application:

 private void registerAPI() {

    customDialog = new CustomDialog(context);
    customDialog.setCancelable(false);
    if (customDialog != null)
        customDialog.show();
    JSONObject object = new JSONObject();
    try {
        object.put("device_type", "android");
        object.put("device_id", device_UDID);
        object.put("device_token", device_token);
        object.put("login_by", "manual");
        object.put("first_name", first_name.getText().toString());
        object.put("last_name", last_name.getText().toString());
        object.put("email", email.getText().toString());
        object.put("password", password.getText().toString());
        object.put("password_confirmation", password.getText().toString());
        object.put("mobile", SharedHelper.getKey(RegisterActivity.this, "mobile"));

    } catch (JSONException e) {
        e.printStackTrace();
    }

    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, URLHelper.register, object, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            if (customDialog != null && customDialog.isShowing())
                customDialog.dismiss();
            utils.print("SignInResponse", response.toString());

            SharedHelper.putKey(RegisterActivity.this, "email", email.getText().toString());
            SharedHelper.putKey(RegisterActivity.this, "password", password.getText().toString());
            signIn();
        }

    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (customDialog != null && customDialog.isShowing())
                customDialog.dismiss();
            String json = null;
            String Message;
            NetworkResponse response = error.networkResponse;
            if (response != null && response.data != null) {
                Log.e("Error SignIN","::"+response.data.toString());
                Log.e("Error SignIN","::"+response.toString());
                utils.print("MyTestError1", "" + response.statusCode);
                try {
                    JSONObject errorObj = new JSONObject(new String(response.data));
                    utils.print("ErrorInRegisterAPI", "" + errorObj.toString());

                    if (response.statusCode == 400 || response.statusCode == 405 || response.statusCode == 500) {
                        try {
                            displayMessage(errorObj.optString("error"));
                        } catch (Exception e) {
                            displayMessage(getString(R.string.something_went_wrong));
                        }
                    } else if (response.statusCode == 401) {
                        try {
                            if (errorObj.optString("message").equalsIgnoreCase("invalid_token")) {
                                //Call Refresh token
                            } else {
                                displayMessage(errorObj.optString("message"));
                            }
                        } catch (Exception e) {
                            displayMessage(getString(R.string.something_went_wrong));
                        }

                    } else if (response.statusCode == 422) {
                        json = trimMessage(new String(response.data));
                        if (json != "" && json != null) {
                            if (json.startsWith("The email has already been taken")) {
                                displayMessage(getString(R.string.email_exist));
                            }else{
                                displayMessage(getString(R.string.something_went_wrong));
                            }
                            //displayMessage(json);
                        } else {
                            displayMessage(getString(R.string.please_try_again));
                        }

                    } else {
                        displayMessage(getString(R.string.please_try_again));
                    }

                } catch (Exception e) {
                    displayMessage(getString(R.string.something_went_wrong));
                }
            } else {
                if (error instanceof NoConnectionError) {
                    displayMessage(getString(R.string.oops_connect_your_internet));
                } else if (error instanceof NetworkError) {
                    displayMessage(getString(R.string.oops_connect_your_internet));
                } else if (error instanceof TimeoutError) {
                    registerAPI();
                }
            }
        }
    }) {

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<String, String>();
            headers.put("X-Requested-With", "XMLHttpRequest");
            return headers;
        }
    };
    AayoCabApplication.getInstance().addToRequestQueue(jsonObjectRequest);
}

Solution

  • It was problem with the end point of an API. It was solved by changing api/provider/register to api/provider/sth. It was due to the use of predefined variable in laravel.