Closed mateusjunges closed 4 years ago
While using this library, i have tried to send a POST request with this JSON object:
{ "geojson": [ { "type": "Feature", "properties": { "party": "Republican" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -104.05, 48.99 ], [ -97.22, 48.98 ], [ -96.58, 45.94 ], [ -104.03, 45.94 ], [ -104.05, 48.99 ] ] ] } }, { "type": "Feature", "properties": { "party": "Democrat" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -109.05, 41.00 ], [ -102.06, 40.99 ], [ -102.03, 36.99 ], [ -109.04, 36.99 ], [ -109.05, 41.00 ] ] ] } } ], "tileserverUrl": "http://ysera.openstreetmap.org/{z}/{x}/{y}.png", "imagemin": "true" }
It sent back to me the following error:
Error: Syntax Error: Unexpected identifier
While debugging, i figured out that the geojson object received via GET (which works fine) and via POST was different.
geojson
GET
POST
This is the gejson received via GET method:
[ { "type":"Feature", "properties":{ "party":"Republican" }, "geometry":{ "type":"Polygon", "coordinates":[ [ [ -104.05, 48.99 ], [ -97.22, 48.98 ], [ -96.58, 45.94 ], [ -104.03, 45.94 ], [ -104.05, 48.99 ] ] ] } }, { "type":"Feature", "properties":{ "party":"Democrat" }, "geometry":{ "type":"Polygon", "coordinates":[ [ [ -109.05, 41.00 ], [ -102.06, 40.99 ], [ -102.03, 36.99 ], [ -109.04, 36.99 ], [ -109.05, 41.00 ] ] ] } } ]
And this is the geojson received via POST:
[ { "type":"Feature", "properties":{ "party":"Republican" }, "geometry":{ "type":"Polygon", "coordinates":[ "Array" ] } }, { "type":"Feature", "properties":{ "party":"Democrat" }, "geometry":{ "type":"Polygon", "coordinates":[ "Array" ] } } ]
I fixed it by adding a JSON.stringfy(options.geojson) if the request was sent via POST method. This PR does not introduce breaking changes.
JSON.stringfy(options.geojson)
Thanks!
Thanks a lot for the pull request, I ended up fixing it in another way, that was the same I applied to other object arguments
@mateusjunges also published fix in v3.5.1
@jperelli Thanks!
While using this library, i have tried to send a POST request with this JSON object:
It sent back to me the following error:
While debugging, i figured out that the
geojson
object received viaGET
(which works fine) and viaPOST
was different.This is the gejson received via
GET
method:And this is the geojson received via
POST
:I fixed it by adding a
JSON.stringfy(options.geojson)
if the request was sent viaPOST
method. This PR does not introduce breaking changes.Thanks!