camomile-project / camomile-server

Collaborative annotation of multimedia documents
http://camomile-project.github.io/
MIT License
12 stars 4 forks source link

consistent response format #79

Closed francoisromain closed 6 years ago

francoisromain commented 6 years ago

Sometimes the api response is a message (ie: login respond with "success": "Authentication succeeded.") sometimes it's an object (ie: me respond with { "_id": "555299eff80f910100d741d1", "description": "", "role": "user", "username": "johndoe" }). It would be cleaner to make it consistent.

For example follow jsend specs:

Successful request:

{
  "status": "success",
  "data": {
    /* Application-specific data would go here. */
  },
  "message": null /* Or optional success message */
}

Failed request:

{
  "status": "error",
  "data": null, /* or optional error payload */
  "message": "Error xyz has occurred"
}
francoisromain commented 6 years ago

following up: login could return infos about the logged-in user:


{
  "status": "success",
  "data": {
    "_id": 123456,
    "name": "Lulu",
    "description": "Lulu desc…"
  },
  "message": "User logged in"
}
hbredin commented 6 years ago

I just started a new branch which should address the main point: consistent response format.

hbredin commented 6 years ago

Available for testing in branch develop since commit 15bee85

Note that /login route has not yet been updated but a new issue #83 has been created to keep track of this request.

francoisromain commented 6 years ago

It seems to work fine, but now there is an error 500 on update actions with corpora, media, layers and annotations (updates only work fine on users and groups).

hbredin commented 6 years ago

I cannot reproduce the error locally:

>>> from camomile import Camomile
>>> client = Camomile('http://localhost:3000')
>>> client.login(USERNAME, PASSWORD)
>>> result = client.updateCorpus(CORPUS_ID, description={'test': 'test'})
>>> print(result['status'])
success
>>> print(result['data']['description'])
{'test': 'test'}

Can you please clarify?

francoisromain commented 6 years ago

When I try to update a corpus / media / layer / annotation from camomile-ui, using camomile-server and camomile-client-javascript, it returns an error 500.

The error logged from camomile-ui does not say much:

Warning: a promise was rejected with a non-error: [object Undefined]

It comes from the bluebird library used by request-promise (http://bluebirdjs.com/docs/warning-explanations.html)

The error logged from camomile-client-javascript points to MongoDB:

"StatusCodeError: 500 - {"status":"error","data":null,"message":{"name":"MongoError","message":"Unknown modifier: $pushAll","driver":true,"index":0,"code":9,"errmsg":"Unknown modifier: $pushAll"}}
    at new StatusCodeError (webpack-internal:///../camomile-client-javascript/node_modules/request-promise-core/lib/errors.js:32:15)

$pushAll is deprecated since v.2.4 of mongodb (-> https://docs.mongodb.com/manual/reference/operator/update/push/)

Do you have an idea?

hbredin commented 6 years ago

Might be related to https://github.com/Automattic/mongoose/issues/5870

hbredin commented 6 years ago

and this: https://github.com/Automattic/mongoose/issues/4455

hbredin commented 6 years ago

Downgrading MongoDB to < 3.6 should solve the problem until mongoose 5.x is out.

hbredin commented 6 years ago

Just opened issue #85 as this is in fact not related to this one... Closing this one, then...