Skip to content

Commit

Permalink
placate typescript 4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
AprilArcus committed Aug 31, 2021
1 parent 99db26d commit 1d39ec0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/sdk-rtl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@looker/sdk-rtl",
"version": "21.0.19",
"version": "21.0.20",
"description": "Looker SDK Runtime Library",
"main": "lib/index.js",
"module": "lib/esm/index.js",
Expand Down
4 changes: 3 additions & 1 deletion packages/sdk-rtl/src/browserTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
responseMode,
ResponseMode,
safeBase64,
isErrorLike,
} from './transport'
import { BaseTransport } from './baseTransport'
import { ICryptoHash } from './cryptoHash'
Expand Down Expand Up @@ -297,7 +298,8 @@ export class BrowserTransport extends BaseTransport {
res
)
return result
} catch (e) {
} catch (e: unknown) {
if (!isErrorLike(e)) throw e
const error: ISDKError = {
message:
typeof e.message === 'string'
Expand Down
15 changes: 15 additions & 0 deletions packages/sdk-rtl/src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,18 @@ export function safeBase64(u8: Uint8Array) {
const rawBase64 = btoa(String.fromCharCode(...u8))
return rawBase64.replace(/\+/g, '-').replace(/\//g, '_')
}

/**
* Type predicate. Asserts that a given object is error-like.
* @param error a value of unknown type
* @return boolean true if the error has a `message` key of type string.
*/
export function isErrorLike<T extends unknown>(
error: T
): error is T & { message: string } {
if (typeof error !== 'object') return false
if (!error) return false
if (!Object.prototype.hasOwnProperty.call(error, 'message')) return false
if (typeof (error as { message: unknown }).message !== 'string') return false
return true
}

0 comments on commit 1d39ec0

Please sign in to comment.