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

Display server error in the page #214

Merged
merged 1 commit into from
Oct 1, 2024

Conversation

zonia3000
Copy link
Contributor

Hi,
currently, if the server replies with an error, vizarr displays a black page. We would like to display an informative error to the user, so we are proposing these changes.

Notice that, since we are also using authentication, we would also like to display 403 Forbidden messages, but this is not possible at the moment since Zarrita handles 403 and 404 in the same way.

Here is the handle_response function in zarrita.js (see https://github.com/manzt/zarrita.js/blob/7ff33a59803ee37cbeec5b4aa61528d8bd021691/packages/storage/src/fetch.ts#L19):

async function handle_response(
	response: Response,
): Promise<Uint8Array | undefined> {
	if (response.status === 404 || response.status === 403) {
		return undefined;
	}
	if (response.status === 200 || response.status === 206) {
		return new Uint8Array(await response.arrayBuffer());
	}
	throw new Error(
		`Unexpected response status ${response.status} ${response.statusText}`,
	);
}

@manzt Would it be possible to throw an error also for the 403 case?

Thanks

Copy link
Member

@manzt manzt left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution. It would be nice to have some kind of toast message but I think this is a better helper to end users than what we currently have (opening the console).

I might take a stab later to toy around with the UI but let's merge for now.

Notice that, since we are also using authentication, we would also like to display 403 Forbidden messages, but this is not possible at the moment since Zarrita handles 403 and 404 in the same way.

I didn't realize this was a behavior change from Zarr.js - so thanks for pointing this out. I'm trying to remember why we also handled 403 this way, but can't find anything. Let me ask some folks in the group, but I think a PR to zarrita changing the default behavior to only returning undefined for 404 would be preferrable.

@manzt manzt merged commit ede3232 into hms-dbmi:main Oct 1, 2024
6 checks passed
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.

2 participants