Skip to content

Commit 8d5ce9f

Browse files
committed
【fix】修复ICL1331,service相关回调代码中发生编码错误不再进入失败回调 review by luoxiao
1 parent aea6b78 commit 8d5ce9f

File tree

2 files changed

+71
-19
lines changed

2 files changed

+71
-19
lines changed

src/common/iServer/CommonServiceBase.js

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export class CommonServiceBase {
3737

3838
this.proxy = null;
3939

40-
4140
this.index = null;
4241

4342
this.length = null;
@@ -274,7 +273,7 @@ export class CommonServiceBase {
274273
timeout: options.async ? 0 : null,
275274
proxy: options.proxy
276275
})
277-
.then(function(response) {
276+
.then(function (response) {
278277
if (response.text) {
279278
return response.text();
280279
}
@@ -283,34 +282,41 @@ export class CommonServiceBase {
283282
}
284283
return response;
285284
})
286-
.then(function(text) {
287-
var result = text;
285+
.then(function (text) {
286+
let requestResult = text;
288287
if (typeof text === 'string') {
289-
result = new JSONFormat().read(text);
288+
requestResult = new JSONFormat().read(text);
290289
}
291-
if (!result || result.error || (result.code >= 300 && result.code !== 304)) {
292-
if (result && result.error) {
293-
result = {
294-
error: result.error
290+
if (
291+
!requestResult ||
292+
requestResult.error ||
293+
(requestResult.code >= 300 && requestResult.code !== 304)
294+
) {
295+
if (requestResult && requestResult.error) {
296+
requestResult = {
297+
error: requestResult.error
295298
};
296299
} else {
297-
result = {
298-
error: result
300+
requestResult = {
301+
error: requestResult
299302
};
300303
}
301304
}
302-
if (result.error) {
305+
return requestResult;
306+
})
307+
.catch(function (e) {
308+
var failure = options.scope ? FunctionExt.bind(options.failure, options.scope) : options.failure;
309+
failure(e);
310+
})
311+
.then((requestResult) => {
312+
if (requestResult.error) {
303313
var failure = options.scope ? FunctionExt.bind(options.failure, options.scope) : options.failure;
304-
failure(result);
314+
failure(requestResult);
305315
} else {
306-
result.succeed = result.succeed == undefined ? true : result.succeed;
316+
requestResult.succeed = requestResult.succeed == undefined ? true : requestResult.succeed;
307317
var success = options.scope ? FunctionExt.bind(options.success, options.scope) : options.success;
308-
success(result);
318+
success(requestResult);
309319
}
310-
})
311-
.catch(function(e) {
312-
var failure = options.scope ? FunctionExt.bind(options.failure, options.scope) : options.failure;
313-
failure(e);
314320
});
315321
}
316322
}

test/openlayers/services/GetFeaturesByBufferSpec.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,50 @@ describe('openlayers_FeatureService_getFeaturesByBuffer', () => {
125125
done();
126126
});
127127
});
128+
it('getFeaturesByBuffer_ICL1331', done => {
129+
var polygon = new Polygon([
130+
[
131+
[-20, 20],
132+
[-20, -20],
133+
[20, -20],
134+
[20, 20],
135+
[-20, 20]
136+
]
137+
]);
138+
var bufferParam = new GetFeaturesByBufferParameters({
139+
datasetNames: ['World:Capitals'],
140+
bufferDistance: 10,
141+
geometry: polygon,
142+
fromIndex: 1,
143+
toIndex: 3
144+
});
145+
var getFeaturesByBuffeService = new FeatureService(featureServiceURL, options);
146+
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl, params, options) => {
147+
expect(method).toBe('POST');
148+
expect(testUrl).toBe(featureServiceURL + '/featureResults?returnContent=true&fromIndex=1&toIndex=3');
149+
var paramsObj = JSON.parse(params.replace(/'/g, '"'));
150+
expect(paramsObj.datasetNames[0]).toBe('World:Capitals');
151+
expect(paramsObj.bufferDistance).toEqual(10);
152+
expect(paramsObj.getFeatureMode).toBe('BUFFER');
153+
expect(options).not.toBeNull();
154+
return Promise.resolve(new Response(JSON.stringify(getFeaturesResultJson)));
155+
});
156+
let errorCalled = false;
157+
let callback = false;
158+
setTimeout(()=>{
159+
expect(callback).toBeTrue();
160+
expect(errorCalled).toBeFalse();
161+
done();
162+
},5000)
163+
getFeaturesByBuffeService.getFeaturesByBuffer(bufferParam, testResult => {
164+
callback= true;
165+
serviceResult = testResult;
166+
if(serviceResult.type == "processFailed"){
167+
errorCalled = true;
168+
}else{
169+
expect(serviceResult.type).toBe('processCompleted');
170+
serviceResult[AAA]
171+
}
172+
});
173+
});
128174
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy