trustsystems / elfinder-java-connector

elFinder Java plugin implementation
Other
30 stars 17 forks source link

Error handling in AbstractJsonCommand #5

Open evazquezma opened 8 years ago

evazquezma commented 8 years ago

Hi

First of all, this is great project and saved us a lot of time. Thank you very much.

I think I found a small error in AbstractJsonCommand class. When an exception occurs, the error message is not being written in the response and elFinder shows an error blaming the JSON response.

I solved the problem with this change:

` @Override final public void execute(ElfinderStorage elfinderStorage, HttpServletRequest request, HttpServletResponse response) throws Exception { JSONObject json = new JSONObject();

    PrintWriter writer = response.getWriter();
    try {
        execute(elfinderStorage, request, json);
        response.setContentType(APPLICATION_JSON_CHARSET_UTF_8);
        json.write(writer);
        writer.flush();
    } catch (Exception e) {
        logger.error("Unable to execute abstract json command", e);
        json.put(ElFinderConstants.ELFINDER_JSON_RESPONSE_ERROR, e.getMessage());
        json.write(writer);
        writer.flush();
    }
    finally {
        writer.close();
    }
}`

As you can see, now the JSONObject is always written, and the exception getMessage is shown in the cliente side.

Thanks

wendersonferreira commented 8 years ago

@evazquezma

first thank you for sharing your vision with us, in fact our intention with this project was to help everyone. I understand and agree with your changes, I leave open that if you want and think you just create a pool request for this change to its credit.

Thank you so much.