Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

500 Internal Server Error on save #83

Open
hecnabae opened this issue Oct 16, 2015 · 1 comment
Open

500 Internal Server Error on save #83

hecnabae opened this issue Oct 16, 2015 · 1 comment

Comments

@hecnabae
Copy link

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
Copy link

farruxx commented Mar 1, 2016

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants