parse-community / parse-server

Parse Server for Node.js / Express
https://parseplatform.org
Apache License 2.0
20.9k stars 4.78k forks source link

Error Code for Invalid Geojson #7331

Open mstniy opened 3 years ago

mstniy commented 3 years ago

New Issue Checklist

Issue Description

Currently there is no error code that signifies an invalid geojson. If the creation or the update of an object fails due to a column with a geospatial index (such as 2dsphere) containing invalid data, Parse throws a generic INTERNAL_SERVER_ERROR with no information as to exactly what went wrong. Note that this corresponds to the Mongo error code 16755.

Steps to reproduce

  1. Create a new class, geojson_test
  2. Create a new column, called geometry, of type Object You can use the dashboard for both of these steps
  3. Create a geospatial index using the mongo shell: db.geojson_test.createIndex({"geometry": "2dsphere"})
  4. Attempt to create this object, using any sdk (JS, rest, ...): { "geometry": {"foo":"bar"} }

One can also create an object with an empty geometry field and later attempt to update it to { "geometry": {"foo":"bar"}} and get the same behaviour.

Actual Outcome

Parse throws a generic INTERNAL_SERVER_ERROR with no information as to exactly what went wrong: { "code": 1, "message": "Internal server error." }

This makes it difficult to handle invalid geojsons programmatically. Note that the original Mongo exception gets logged by Parse, but is programmatically inaccessible.

Expected Outcome

A helpful error message, like the one returned by Mongo: MongoError: Can't extract geo keys: ... unknown GeoJSON type: { foo: "bar" }

Failing Test Case / Pull Request

Environment

Server

Database

Client

Logs

See above

mtrezza commented 3 years ago

Thanks for reporting!

I agree that the server should not crash but provide a proper error message. The steps would be:

mtrezza commented 3 years ago

This issue has been classified as bug with severity S4 (small/trivial):

mstniy commented 3 years ago

I have created a PR for the new error code parse-community/Parse-SDK-JS#1342

mtrezza commented 3 years ago

The error code PR has been merged.

The error code won't be available until a new Parse JS SDK will be released and the dependency in Parse Server is updated. But you can already expect the Parse Error and write tests for it, they will just fail for now.

parse-github-assistant[bot] commented 2 years ago

Thanks for opening this issue!