one
Version:
One is a React framework for web, iOS, and Android apps.
19 lines (17 loc) • 843 B
text/typescript
// native failures cross nitro as one message, "<code>: <Namespace>.<verb>:
// <detail>", and android appends a newline to every rejection. sync throws add
// a "<Hybrid>.<method>(...): " prefix ahead of the code instead. this trims
// the newline and restores the stable code on the error the caller sees, so
// callers branch on `code` as they did with the bridge modules.
export function rethrowNativeError(error: unknown): never {
if (error instanceof Error) {
const message = error.message.trimEnd()
const coded = /(?:^|:\s)((?:E|ERR)_[A-Z0-9_]+): ([\s\S]*)$/.exec(message)
error.message = coded ? coded[2] : message
if (coded) Object.assign(error, { code: coded[1] })
}
throw error
}
export function missingNativeBuild(operation: string): Error {
return new Error(`${operation} needs an iOS or Android build`)
}