diff --git a/api.js b/api.js index dcb81af..7a8b677 100644 --- a/api.js +++ b/api.js @@ -1,3 +1,10 @@ +/** + * Thrown when the response is technically a "success" one, but the returned data is not what it should be. + */ + +class ResponseDataError extends Error {} + + /** * Thrown when the passed URL is not a supported post URL on bsky.app. */ @@ -145,15 +152,20 @@ class BlueskyAPI extends Minisky { /** @param {string} handle, @returns {Promise} */ async resolveHandle(handle) { - let did = this.handleCache.getHandleDid(handle); + let cachedDid = this.handleCache.getHandleDid(handle); - if (did) { - return did; + if (cachedDid) { + return cachedDid; } else { let json = await this.getRequest('com.atproto.identity.resolveHandle', { handle }, { auth: false }); - did = json['did']; - this.handleCache.setHandleDid(handle, did); - return did; + let did = json['did']; + + if (did) { + this.handleCache.setHandleDid(handle, did); + return did; + } else { + throw new ResponseDataError('Missing DID in response: ' + JSON.stringify(json)); + } } } diff --git a/jsconfig.json b/jsconfig.json index cd4b961..772516a 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -3,7 +3,9 @@ "target": "es2022", "checkJs": true, "strict": true, - "noImplicitAny": false + "noImplicitAny": false, + "exactOptionalPropertyTypes": true, + "useUnknownInCatchVariables": false }, "include": ["*.js", "*.d.ts"] } diff --git a/skythread.js b/skythread.js index 0c52361..ced6999 100644 --- a/skythread.js +++ b/skythread.js @@ -1,7 +1,6 @@ function init() { - /** @type {AnyElement} */ - let document = window.document; - let html = document.body.parentNode; + let document = /** @type {AnyElement} */ (/** @type {unknown} */ (window.document)); + let html = /** @type {AnyElement} */ (/** @type {unknown} */ (window.document.body.parentNode)); window.dateLocale = localStorage.getItem('locale') || undefined; diff --git a/types.d.ts b/types.d.ts index 7edf972..fbe11c8 100644 --- a/types.d.ts +++ b/types.d.ts @@ -1,7 +1,7 @@ interface Window { unauthed: boolean; root: AnyPost; - dateLocale?: string; + dateLocale: string | undefined; } declare var api: BlueskyAPI;