mirror of
https://github.com/withastro/astro.git
synced 2025-01-20 22:12:38 -05:00
add error message for svg without dimensions (#10924)
* add svg * throw clean error * add error handling * revert * throw clean error * add changeset * make it a patch * Update remoteProbe.ts --------- Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
This commit is contained in:
parent
303968bd72
commit
3a0c02ae03
2 changed files with 23 additions and 12 deletions
5
.changeset/cold-dolls-do.md
Normal file
5
.changeset/cold-dolls-do.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"astro": patch
|
||||
---
|
||||
|
||||
Handle image-size errors by displaying a clearer message
|
|
@ -6,22 +6,28 @@ export async function imageMetadata(
|
|||
data: Uint8Array,
|
||||
src?: string
|
||||
): Promise<Omit<ImageMetadata, 'src' | 'fsPath'>> {
|
||||
const result = probe(data);
|
||||
try {
|
||||
const result = probe(data);
|
||||
if (!result.height || !result.width || !result.type) {
|
||||
throw new AstroError({
|
||||
...AstroErrorData.NoImageMetadata,
|
||||
message: AstroErrorData.NoImageMetadata.message(src),
|
||||
});
|
||||
}
|
||||
|
||||
if (!result.height || !result.width || !result.type) {
|
||||
const { width, height, type, orientation } = result;
|
||||
const isPortrait = (orientation || 0) >= 5;
|
||||
|
||||
return {
|
||||
width: isPortrait ? height : width,
|
||||
height: isPortrait ? width : height,
|
||||
format: type as ImageInputFormat,
|
||||
orientation,
|
||||
};
|
||||
} catch (e) {
|
||||
throw new AstroError({
|
||||
...AstroErrorData.NoImageMetadata,
|
||||
message: AstroErrorData.NoImageMetadata.message(src),
|
||||
});
|
||||
}
|
||||
|
||||
const { width, height, type, orientation } = result;
|
||||
const isPortrait = (orientation || 0) >= 5;
|
||||
|
||||
return {
|
||||
width: isPortrait ? height : width,
|
||||
height: isPortrait ? width : height,
|
||||
format: type as ImageInputFormat,
|
||||
orientation,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue