Skip to content

Commit

Permalink
Swap raw fetch for _requestJson call
Browse files Browse the repository at this point in the history
  • Loading branch information
madole committed May 20, 2022
1 parent dbd0121 commit 2082b46
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,7 @@ export default class FeatureService {

return new Promise((resolve) => {
fetch(`${`${this._esriServiceOptions.url}/query?${params.toString()}`}`, this._esriServiceOptions.fetchOptions)
.then((response) => { //eslint-disable-line
return this._esriServiceOptions.f === 'pbf' ? response.arrayBuffer() : response.json()
})
.then(response => (this._esriServiceOptions.f === 'pbf' ? response.arrayBuffer() : response.json()))
.then((data) => {
let out
try {
Expand Down Expand Up @@ -319,20 +317,15 @@ export default class FeatureService {
const params = new URLSearchParams({f: 'json'})

this._appendTokenIfExists(params)

return new Promise((resolve, reject) => {
fetch(`${this._esriServiceOptions.url}?${params.toString()}`, this._esriServiceOptions.fetchOptions)
.then(response => response.json())
.then((data) => {
// Esri sends error responses with a 200 status code, so handle them in `.then`
if (data.error) {
throw new Error(JSON.stringify(data.error))
}
this.serviceMetadata = data
resolve(this.serviceMetadata)
})
.catch(err => reject(err))
})
return this._requestJson(`${this._esriServiceOptions.url}?${params.toString()}`, this._esriServiceOptions.fetchOptions)
.then((data) => {
// Esri sends error responses with a 200 status code, so handle them in `.then`
if (data.error) {
throw new Error(JSON.stringify(data.error))
}
this.serviceMetadata = data
return (this.serviceMetadata)
})
}

getFeaturesByLonLat(lnglat, radius, returnGeometry) {
Expand Down

0 comments on commit 2082b46

Please sign in to comment.