-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: investigate login error [INS-3851] #7438
chore: investigate login error [INS-3851] #7438
Conversation
4f6cb82
to
de26010
Compare
|
||
export async function decodeBase64(base64: string): Promise<Uint8Array> { | ||
try { | ||
let uri = 'data:application/octet-binary;base64,'; | ||
uri += base64; | ||
const res = await fetch(uri); | ||
const buffer = await res.arrayBuffer(); | ||
return new Uint8Array(buffer); | ||
|
||
} catch (error) { | ||
console.error(error); | ||
throw new Error('Failed to decode base64'); | ||
} | ||
} | ||
|
||
export async function encodeBase64(data: Uint8Array): Promise<string> { | ||
const dataUri = await new Promise<string>((resolve, reject) => { | ||
const reader = new FileReader(); | ||
reader.onload = () => { | ||
if (typeof reader.result === 'string') { | ||
resolve(reader.result); | ||
} else { | ||
reject(); | ||
} | ||
}; | ||
reader.onerror = reject; | ||
reader.readAsDataURL(new Blob([data])); | ||
}); | ||
|
||
const dataAt = dataUri.indexOf(','); | ||
if (dataAt === -1) { | ||
throw new Error(`unexpected data uri output: ${dataUri}`); | ||
} | ||
|
||
return dataUri.slice(dataAt + 1); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was pulled out of api-cilent code to make it clearer it was going to use insomniaFetch, no sure if this is desirable @gatzjames to decide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes lets deprecate the api-client
console.error(error); | ||
return error.toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.error(error); | |
return error.toString(); | |
console.error(error); | |
return error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit of a smell and likely to cause a bug now or in a future change, might help to consider a few angles here
ac349d8
to
32c13e7
Compare
|
||
export async function decodeBase64(base64: string): Promise<Uint8Array> { | ||
try { | ||
let uri = 'data:application/octet-binary;base64,'; | ||
uri += base64; | ||
const res = await fetch(uri); | ||
const buffer = await res.arrayBuffer(); | ||
return new Uint8Array(buffer); | ||
|
||
} catch (error) { | ||
console.error(error); | ||
throw new Error('Failed to decode base64'); | ||
} | ||
} | ||
|
||
export async function encodeBase64(data: Uint8Array): Promise<string> { | ||
const dataUri = await new Promise<string>((resolve, reject) => { | ||
const reader = new FileReader(); | ||
reader.onload = () => { | ||
if (typeof reader.result === 'string') { | ||
resolve(reader.result); | ||
} else { | ||
reject(); | ||
} | ||
}; | ||
reader.onerror = reject; | ||
reader.readAsDataURL(new Blob([data])); | ||
}); | ||
|
||
const dataAt = dataUri.indexOf(','); | ||
if (dataAt === -1) { | ||
throw new Error(`unexpected data uri output: ${dataUri}`); | ||
} | ||
|
||
return dataUri.slice(dataAt + 1); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes lets deprecate the api-client
32c13e7
to
c08038a
Compare
* chore: investigate login error [INS-3851] * another pass at error we show * Update packages/insomnia/src/ui/auth-session-provider.ts
Closes INS-3851
Taking a pass at #7358 (comment)
Trying to surfaces cases where whoami fails