Skip to content

Commit 1cff2be

Browse files
committed
refactor: replace Style.loadURL then/catch with await/catch
1 parent f68fbc9 commit 1cff2be

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/style/style.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,16 @@ export class Style extends Evented {
429429
const request = await this.map._requestManager.transformRequest(url, ResourceType.Style);
430430
this._loadStyleRequest = new AbortController();
431431
const abortController = this._loadStyleRequest;
432-
getJSON<StyleSpecification>(request, this._loadStyleRequest).then((response) => {
432+
try {
433+
const response = await getJSON<StyleSpecification>(request, this._loadStyleRequest);
433434
this._loadStyleRequest = null;
434435
this._load(response.data, options, previousStyle);
435-
}).catch((error) => {
436+
} catch (error) {
436437
this._loadStyleRequest = null;
437438
if (error && !abortController.signal.aborted) { // ignore abort
438439
this.fire(new ErrorEvent(error));
439440
}
440-
});
441+
}
441442
}
442443

443444
loadJSON(json: StyleSpecification, options: StyleSetterOptions & StyleSwapOptions = {}, previousStyle?: StyleSpecification) {

0 commit comments

Comments
 (0)