mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-20 02:37:41 -05:00
Add error codes to our custom errors (#959)
This commit is contained in:
@@ -2,7 +2,8 @@ import { htmlDecode, ensureUniqueId } from '../utils';
|
||||
import type { Runtime } from '../runtime';
|
||||
import { getLogger } from '../logger';
|
||||
import { pyExec } from '../pyexec';
|
||||
import { FetchError, _createAlertBanner } from '../exceptions';
|
||||
import { _createAlertBanner } from '../exceptions';
|
||||
import { robustFetch } from '../fetch';
|
||||
|
||||
const logger = getLogger('py-script');
|
||||
|
||||
@@ -18,17 +19,14 @@ export function make_PyScript(runtime: Runtime) {
|
||||
async getPySrc(): Promise<string> {
|
||||
if (this.hasAttribute('src')) {
|
||||
const url = this.getAttribute('src');
|
||||
const response = await fetch(url);
|
||||
if (response.status !== 200) {
|
||||
const errorMessage = (
|
||||
`Failed to fetch '${url}' - Reason: ` +
|
||||
`${response.status} ${response.statusText}`
|
||||
);
|
||||
_createAlertBanner(errorMessage);
|
||||
try {
|
||||
const response = await robustFetch(url);
|
||||
return await response.text();
|
||||
} catch(e) {
|
||||
_createAlertBanner(e.message);
|
||||
this.innerHTML = '';
|
||||
throw new FetchError(errorMessage);
|
||||
throw e
|
||||
}
|
||||
return await response.text();
|
||||
} else {
|
||||
return htmlDecode(this.innerHTML);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user