strongloop-community / loopback-sdk-android

Android Client SDK for the LoopBack framework.
Other
67 stars 45 forks source link

500 Internal Server Error on save #83

Open hecnabae opened 8 years ago

hecnabae commented 8 years ago

Hello , I get 500 Internal Server Error when trying to save an entity. I'm using the mongodb connector. What can be the cause? Entity :

 {
  "name": "Libro",
  "plural": "libros",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "title": {
      "type": "string",
      "required": true
    },
    "category": {
      "type": "string",
      "required": true
    },
    "description": {
      "type": "string"
    },
    "location": {
      "type": "string"
    },
    "datePub": {
      "type": "date",
      "required": true
    }
  },
  "validations": [],
  "relations": {
    "people": {
      "type": "hasAndBelongsToMany",
      "model": "Person",
      "foreignKey": ""
    }
  },
  "acls": [],
  "methods": {}
}

Android code:

RestAdapter adapter = new RestAdapter(getActivity().getApplicationContext(), "http://192.168.1.15:3000/api");

LibroRepository libroRepository = adapter.createRepository(LibroRepository.class);

Libro libro = libroRepository.createObject(ImmutableMap.of("name", "Libro"));
p.setTitle(((EditText) rootView.findViewById(R.id.etTitle)).getText().toString());
p.setCategory(((EditText) rootView.findViewById(R.id.etCategory)).getText().toString());
p.setDescription(((EditText) rootView.findViewById(R.id.etDescription)).getText().toString());
p.setLocation(((EditText) rootView.findViewById(R.id.etLocation)).getText().toString());
DatePicker dp = (DatePicker) rootView.findViewById(R.id.dpDatePub);
Calendar cal = Calendar.getInstance();
cal.set(dp.getYear(), dp.getMonth(), dp.getDayOfMonth());
p.setDatePub(cal.getTime());

                p.save(new VoidCallback() {
                    @Override
                    public void onSuccess() {
                        String ok = "ok";
                    }

                    @Override
                    public void onError(Throwable t) {
                        String err = t.getMessage();
                    }
                });

Model:

public class Libro extends Model{
    private String title;
    private String category;
    private String description;
    private String location;
    private Date datePub;

// Getters and Setters...
}

Thanks in advance!

farruxx commented 8 years ago

Dear Contributors, please add more detail to error handlers. When I get some error, it returns 500, even if I add some non-unique value to the table. When I put breakpoints, there is a usefull information, that can be used for processing the error, but by default callback doesn't return it. For example, in RestAdapter.java:

  @Override
        public void onFailure(int statusCode,
                              org.apache.http.Header[] headers,
                              byte[] responseBody,
                              java.lang.Throwable error) {

resonseBody has has information about what happend, but it didn't used in code: callback.onError(error);