src/app/routes/error/getInitialData/index.js

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import { ERROR_PAGE } from '#app/routes/utils/pageTypes';
import { matchRoutes } from 'react-router-config';

export default pathRegex =>
  ({ path: pathname }) => {
    const matchingRoute = matchRoutes([{ path: pathRegex }], pathname);

    const errorCode = Number(
      matchingRoute?.[0]?.match?.params?.errorCode || 404,
    );

    return Promise.resolve({
      status: 200,
      errorCode,
      pageData: { metadata: { type: ERROR_PAGE } },
    });
  };