Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | 41x 41x 41x 41x 41x 41x 41x 41x 1x 82x 82x 41x 41x 41x 41x 41x 41x 41x 41x 41x 82x 25x 57x 42x 82x 1x 103x 17x | import defined from "./defined.js";
import formatError from "./formatError.js";
/**
* Provides details about an error that occurred in an {@link ImageryProvider} or a {@link TerrainProvider}.
*
* @alias TileProviderError
* @constructor
*
* @param {ImageryProvider|TerrainProvider} provider The imagery or terrain provider that experienced the error.
* @param {string} message A message describing the error.
* @param {number} [x] The X coordinate of the tile that experienced the error, or undefined if the error
* is not specific to a particular tile.
* @param {number} [y] The Y coordinate of the tile that experienced the error, or undefined if the error
* is not specific to a particular tile.
* @param {number} [level] The level of the tile that experienced the error, or undefined if the error
* is not specific to a particular tile.
* @param {number} [timesRetried=0] The number of times this operation has been retried.
* @param {Error} [error] The error or exception that occurred, if any.
*/
function TileProviderError(
provider,
message,
x,
y,
level,
timesRetried,
error,
) {
/**
* The {@link ImageryProvider} or {@link TerrainProvider} that experienced the error.
* @type {ImageryProvider|TerrainProvider}
*/
this.provider = provider;
/**
* The message describing the error.
* @type {string}
*/
this.message = message;
/**
* The X coordinate of the tile that experienced the error. If the error is not specific
* to a particular tile, this property will be undefined.
* @type {number}
*/
this.x = x;
/**
* The Y coordinate of the tile that experienced the error. If the error is not specific
* to a particular tile, this property will be undefined.
* @type {number}
*/
this.y = y;
/**
* The level-of-detail of the tile that experienced the error. If the error is not specific
* to a particular tile, this property will be undefined.
* @type {number}
*/
this.level = level;
/**
* The number of times this operation has been retried.
* @type {number}
* @default 0
*/
this.timesRetried = timesRetried ?? 0;
/**
* True if the failed operation should be retried; otherwise, false. The imagery or terrain provider
* will set the initial value of this property before raising the event, but any listeners
* can change it. The value after the last listener is invoked will be acted upon.
* @type {boolean}
* @default false
*/
this.retry = false;
/**
* The error or exception that occurred, if any.
* @type {Error}
*/
this.error = error;
}
/**
* Reports an error in an {@link ImageryProvider} or {@link TerrainProvider} by raising an event if it has any listeners, or by
* logging the error to the console if the event has no listeners. This method also tracks the number
* of times the operation has been retried.
*
* @param {TileProviderError} previousError The error instance returned by this function the last
* time it was called for this error, or undefined if this is the first time this error has
* occurred.
* @param {ImageryProvider|TerrainProvider} [provider] The imagery or terrain provider that encountered the error.
* @param {Event} [event] The event to raise to inform listeners of the error.
* @param {string} [message] The message describing the error.
* @param {number} [x] The X coordinate of the tile that experienced the error, or undefined if the
* error is not specific to a particular tile.
* @param {number} [y] The Y coordinate of the tile that experienced the error, or undefined if the
* error is not specific to a particular tile.
* @param {number} [level] The level-of-detail of the tile that experienced the error, or undefined if the
* error is not specific to a particular tile.
* @param {Error} [errorDetails] The error or exception that occurred, if any.
* @returns {TileProviderError} The error instance that was passed to the event listeners and that
* should be passed to this function the next time it is called for the same error in order
* to track retry counts.
*/
TileProviderError.reportError = function (
previousError,
provider,
event,
message,
x,
y,
level,
errorDetails,
) {
let error = previousError;
if (!defined(previousError)) {
error = new TileProviderError(
provider,
message,
x,
y,
level,
0,
errorDetails,
);
} else {
error.provider = provider;
error.message = message;
error.x = x;
error.y = y;
error.level = level;
error.retry = false;
error.error = errorDetails;
++error.timesRetried;
}
if (defined(event) && event.numberOfListeners > 0) {
event.raiseEvent(error);
} else if (defined(provider)) {
console.log(
`An error occurred in "${provider.constructor.name}": ${formatError(
message,
)}`,
);
}
return error;
};
/**
* Reports success of an operation by resetting the retry count of a previous error, if any. This way,
* if the error occurs again in the future, the listeners will be informed that it has not yet been retried.
*
* @param {TileProviderError} previousError The previous error, or undefined if this operation has
* not previously resulted in an error.
*/
TileProviderError.reportSuccess = function (previousError) {
if (defined(previousError)) {
previousError.timesRetried = -1;
}
};
/**
* A function that will be called to retry the operation.
* @callback TileProviderError.RetryFunction
*/
export default TileProviderError;
|