Move pagination error to AstroErrorData (#6149)
* Move error to AstroErrorData * Add changeset
This commit is contained in:
parent
6a59531ff9
commit
592386b755
3 changed files with 23 additions and 3 deletions
5
.changeset/breezy-worms-retire.md
Normal file
5
.changeset/breezy-worms-retire.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Moved pagination error to AstroErrorData
|
|
@ -429,6 +429,19 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
message: (name: string) => `Invalid arguments passed to${name ? ` <${name}>` : ''} component.`,
|
||||
hint: 'Astro components cannot be rendered directly via function call, such as `Component()` or `{items.map(Component)}`.',
|
||||
},
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
* - [Pagination](https://docs.astro.build/en/core-concepts/routing/#pagination)
|
||||
* @description
|
||||
* The page number parameter was not found in your filepath.
|
||||
*/
|
||||
PageNumberParamNotFound: {
|
||||
title: 'Page number param not found.',
|
||||
code: 3021,
|
||||
message: (paramName: string) => `[paginate()] page number param \`${paramName}\` not found in your filepath.`,
|
||||
hint: 'Rename your file to \`[page].astro\` or \`[...page].astro\`.'
|
||||
},
|
||||
// Vite Errors - 4xxx
|
||||
UnknownViteError: {
|
||||
title: 'Unknown Vite Error.',
|
||||
|
|
|
@ -6,6 +6,7 @@ import {
|
|||
Props,
|
||||
RouteData,
|
||||
} from '../../@types/astro';
|
||||
import { AstroError, AstroErrorData } from '../errors/index.js';
|
||||
|
||||
export function generatePaginateFunction(routeMatch: RouteData): PaginateFunction {
|
||||
return function paginateUtility(
|
||||
|
@ -23,9 +24,10 @@ export function generatePaginateFunction(routeMatch: RouteData): PaginateFunctio
|
|||
} else if (routeMatch.params.includes(`${paramName}`)) {
|
||||
includesFirstPageNumber = true;
|
||||
} else {
|
||||
throw new Error(
|
||||
`[paginate()] page number param \`${paramName}\` not found in your filepath.\nRename your file to \`[page].astro\` or \`[...page].astro\`.`
|
||||
);
|
||||
throw new AstroError({
|
||||
...AstroErrorData.PageNumberParamNotFound,
|
||||
message: AstroErrorData.PageNumberParamNotFound.message(paramName),
|
||||
});
|
||||
}
|
||||
const lastPage = Math.max(1, Math.ceil(data.length / pageSize));
|
||||
|
||||
|
|
Loading…
Reference in a new issue