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.`,
|
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)}`.',
|
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
|
// Vite Errors - 4xxx
|
||||||
UnknownViteError: {
|
UnknownViteError: {
|
||||||
title: 'Unknown Vite Error.',
|
title: 'Unknown Vite Error.',
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {
|
||||||
Props,
|
Props,
|
||||||
RouteData,
|
RouteData,
|
||||||
} from '../../@types/astro';
|
} from '../../@types/astro';
|
||||||
|
import { AstroError, AstroErrorData } from '../errors/index.js';
|
||||||
|
|
||||||
export function generatePaginateFunction(routeMatch: RouteData): PaginateFunction {
|
export function generatePaginateFunction(routeMatch: RouteData): PaginateFunction {
|
||||||
return function paginateUtility(
|
return function paginateUtility(
|
||||||
|
@ -23,9 +24,10 @@ export function generatePaginateFunction(routeMatch: RouteData): PaginateFunctio
|
||||||
} else if (routeMatch.params.includes(`${paramName}`)) {
|
} else if (routeMatch.params.includes(`${paramName}`)) {
|
||||||
includesFirstPageNumber = true;
|
includesFirstPageNumber = true;
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new AstroError({
|
||||||
`[paginate()] page number param \`${paramName}\` not found in your filepath.\nRename your file to \`[page].astro\` or \`[...page].astro\`.`
|
...AstroErrorData.PageNumberParamNotFound,
|
||||||
);
|
message: AstroErrorData.PageNumberParamNotFound.message(paramName),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
const lastPage = Math.max(1, Math.ceil(data.length / pageSize));
|
const lastPage = Math.max(1, Math.ceil(data.length / pageSize));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue