Skip to content
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

Merged

Conversation

filfreire
Copy link
Member

@filfreire filfreire commented May 21, 2024

Closes INS-3851

Taking a pass at #7358 (comment)

Trying to surfaces cases where whoami fails

image

@filfreire filfreire requested a review from a team May 21, 2024 11:44
@filfreire filfreire marked this pull request as ready for review May 22, 2024 13:16
@filfreire filfreire force-pushed the chore/investigate-loginerror-INS-3851 branch from 4f6cb82 to de26010 Compare May 22, 2024 13:16
Comment on lines +31 to +66

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);
}
Copy link
Contributor

@jackkav jackkav May 22, 2024

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.

Copy link
Contributor

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

Comment on lines 80 to 81
console.error(error);
return error.toString();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.error(error);
return error.toString();
console.error(error);
return error;

Copy link
Contributor

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

@filfreire filfreire requested a review from gatzjames May 22, 2024 13:27
@filfreire filfreire force-pushed the chore/investigate-loginerror-INS-3851 branch 3 times, most recently from ac349d8 to 32c13e7 Compare May 22, 2024 14:41
Comment on lines +31 to +66

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);
}
Copy link
Contributor

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

@filfreire filfreire force-pushed the chore/investigate-loginerror-INS-3851 branch from 32c13e7 to c08038a Compare May 28, 2024 12:24
@filfreire filfreire merged commit 09adb58 into Kong:develop May 28, 2024
7 checks passed
@filfreire filfreire deleted the chore/investigate-loginerror-INS-3851 branch May 28, 2024 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants