Merge pull request #1861 from payloadcms/feat/error-reporting
feat: throws descriptive error when collection or global slug not found
This commit is contained in:
@@ -3,6 +3,7 @@ import forgotPassword, { Result } from '../forgotPassword';
|
||||
import { Payload } from '../../..';
|
||||
import { getDataLoader } from '../../../collections/dataloader';
|
||||
import i18n from '../../../translations/init';
|
||||
import { APIError } from '../../../errors';
|
||||
|
||||
export type Options = {
|
||||
collection: string
|
||||
@@ -25,6 +26,10 @@ async function localForgotPassword(payload: Payload, options: Options): Promise<
|
||||
|
||||
const collection = payload.collections[collectionSlug];
|
||||
|
||||
if (!collection) {
|
||||
throw new APIError(`The collection with slug ${collectionSlug} can't be found.`);
|
||||
}
|
||||
|
||||
req.payloadAPI = 'local';
|
||||
req.i18n = i18n(payload.config.i18n);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import { TypeWithID } from '../../../collections/config/types';
|
||||
import { Payload } from '../../..';
|
||||
import { getDataLoader } from '../../../collections/dataloader';
|
||||
import i18n from '../../../translations/init';
|
||||
import { APIError } from '../../../errors';
|
||||
|
||||
export type Options = {
|
||||
collection: string
|
||||
@@ -21,7 +22,7 @@ export type Options = {
|
||||
showHiddenFields?: boolean
|
||||
}
|
||||
|
||||
async function localLogin<T extends TypeWithID = any>(payload: Payload, options: Options): Promise<Result & { user: T}> {
|
||||
async function localLogin<T extends TypeWithID = any>(payload: Payload, options: Options): Promise<Result & { user: T }> {
|
||||
const {
|
||||
collection: collectionSlug,
|
||||
req = {} as PayloadRequest,
|
||||
@@ -36,6 +37,10 @@ async function localLogin<T extends TypeWithID = any>(payload: Payload, options:
|
||||
|
||||
const collection = payload.collections[collectionSlug];
|
||||
|
||||
if (!collection) {
|
||||
throw new APIError(`The collection with slug ${collectionSlug} can't be found.`);
|
||||
}
|
||||
|
||||
req.payloadAPI = 'local';
|
||||
req.payload = payload;
|
||||
req.i18n = i18n(payload.config.i18n);
|
||||
|
||||
@@ -3,6 +3,7 @@ import resetPassword, { Result } from '../resetPassword';
|
||||
import { PayloadRequest } from '../../../express/types';
|
||||
import { getDataLoader } from '../../../collections/dataloader';
|
||||
import i18n from '../../../translations/init';
|
||||
import { APIError } from '../../../errors';
|
||||
|
||||
export type Options = {
|
||||
collection: string
|
||||
@@ -24,6 +25,10 @@ async function localResetPassword(payload: Payload, options: Options): Promise<R
|
||||
|
||||
const collection = payload.collections[collectionSlug];
|
||||
|
||||
if (!collection) {
|
||||
throw new APIError(`The collection with slug ${collectionSlug} can't be found.`);
|
||||
}
|
||||
|
||||
req.payload = payload;
|
||||
req.payloadAPI = 'local';
|
||||
req.i18n = i18n(payload.config.i18n);
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Payload } from '../../..';
|
||||
import unlock from '../unlock';
|
||||
import { getDataLoader } from '../../../collections/dataloader';
|
||||
import i18n from '../../../translations/init';
|
||||
import { APIError } from '../../../errors';
|
||||
|
||||
export type Options = {
|
||||
collection: string
|
||||
@@ -23,6 +24,10 @@ async function localUnlock(payload: Payload, options: Options): Promise<boolean>
|
||||
|
||||
const collection = payload.collections[collectionSlug];
|
||||
|
||||
if (!collection) {
|
||||
throw new APIError(`The collection with slug ${collectionSlug} can't be found.`);
|
||||
}
|
||||
|
||||
req.payload = payload;
|
||||
req.payloadAPI = 'local';
|
||||
req.i18n = i18n(payload.config.i18n);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { APIError } from '../../../errors';
|
||||
import { Payload } from '../../../index';
|
||||
import verifyEmail from '../verifyEmail';
|
||||
|
||||
@@ -14,6 +15,10 @@ async function localVerifyEmail(payload: Payload, options: Options): Promise<boo
|
||||
|
||||
const collection = payload.collections[collectionSlug];
|
||||
|
||||
if (!collection) {
|
||||
throw new APIError(`The collection with slug ${collectionSlug} can't be found.`);
|
||||
}
|
||||
|
||||
return verifyEmail({
|
||||
token,
|
||||
collection,
|
||||
|
||||
@@ -7,6 +7,7 @@ import create from '../create';
|
||||
import { getDataLoader } from '../../dataloader';
|
||||
import { File } from '../../../uploads/types';
|
||||
import i18n from '../../../translations/init';
|
||||
import { APIError } from '../../../errors';
|
||||
|
||||
export type Options<T> = {
|
||||
collection: string
|
||||
@@ -46,6 +47,10 @@ export default async function createLocal<T = any>(payload: Payload, options: Op
|
||||
const collection = payload.collections[collectionSlug];
|
||||
const defaultLocale = payload?.config?.localization ? payload?.config?.localization?.defaultLocale : null;
|
||||
|
||||
if (!collection) {
|
||||
throw new APIError(`The collection with slug ${collectionSlug} can't be found.`);
|
||||
}
|
||||
|
||||
req.payloadAPI = 'local';
|
||||
req.locale = locale ?? req?.locale ?? defaultLocale;
|
||||
req.fallbackLocale = fallbackLocale ?? req?.fallbackLocale ?? defaultLocale;
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Payload } from '../../../index';
|
||||
import deleteOperation from '../delete';
|
||||
import { getDataLoader } from '../../dataloader';
|
||||
import i18n from '../../../translations/init';
|
||||
import { APIError } from '../../../errors';
|
||||
|
||||
export type Options = {
|
||||
collection: string
|
||||
@@ -32,6 +33,11 @@ export default async function deleteLocal<T extends TypeWithID = any>(payload: P
|
||||
const collection = payload.collections[collectionSlug];
|
||||
const defaultLocale = payload?.config?.localization ? payload?.config?.localization?.defaultLocale : null;
|
||||
|
||||
|
||||
if (!collection) {
|
||||
throw new APIError(`The collection with slug ${collectionSlug} can't be found.`);
|
||||
}
|
||||
|
||||
const req = {
|
||||
user,
|
||||
payloadAPI: 'local',
|
||||
|
||||
@@ -6,6 +6,7 @@ import { PayloadRequest } from '../../../express/types';
|
||||
import find from '../find';
|
||||
import { getDataLoader } from '../../dataloader';
|
||||
import i18n from '../../../translations/init';
|
||||
import { APIError } from '../../../errors';
|
||||
|
||||
export type Options = {
|
||||
collection: string
|
||||
@@ -50,6 +51,10 @@ export default async function findLocal<T extends TypeWithID = any>(payload: Pay
|
||||
const collection = payload.collections[collectionSlug];
|
||||
const defaultLocale = payload?.config?.localization ? payload?.config?.localization?.defaultLocale : null;
|
||||
|
||||
if (!collection) {
|
||||
throw new APIError(`The collection with slug ${collectionSlug} can't be found.`);
|
||||
}
|
||||
|
||||
req.payloadAPI = 'local';
|
||||
req.locale = locale ?? req?.locale ?? defaultLocale;
|
||||
req.fallbackLocale = fallbackLocale ?? req?.fallbackLocale ?? defaultLocale;
|
||||
|
||||
@@ -5,6 +5,7 @@ import findByID from '../findByID';
|
||||
import { Payload } from '../../..';
|
||||
import { getDataLoader } from '../../dataloader';
|
||||
import i18n from '../../../translations/init';
|
||||
import { APIError } from '../../../errors';
|
||||
|
||||
export type Options = {
|
||||
collection: string
|
||||
@@ -41,6 +42,10 @@ export default async function findByIDLocal<T extends TypeWithID = any>(payload:
|
||||
const collection = payload.collections[collectionSlug];
|
||||
const defaultLocale = payload?.config?.localization ? payload?.config?.localization?.defaultLocale : null;
|
||||
|
||||
if (!collection) {
|
||||
throw new APIError(`The collection with slug ${collectionSlug} can't be found.`);
|
||||
}
|
||||
|
||||
req.payloadAPI = 'local';
|
||||
req.locale = locale ?? req?.locale ?? defaultLocale;
|
||||
req.fallbackLocale = fallbackLocale ?? req?.fallbackLocale ?? defaultLocale;
|
||||
|
||||
@@ -5,6 +5,7 @@ import { TypeWithVersion } from '../../../versions/types';
|
||||
import findVersionByID from '../findVersionByID';
|
||||
import { getDataLoader } from '../../dataloader';
|
||||
import i18n from '../../../translations/init';
|
||||
import { APIError } from '../../../errors';
|
||||
|
||||
export type Options = {
|
||||
collection: string
|
||||
@@ -35,6 +36,10 @@ export default async function findVersionByIDLocal<T extends TypeWithVersion<T>
|
||||
const collection = payload.collections[collectionSlug];
|
||||
const defaultLocale = payload?.config?.localization ? payload?.config?.localization?.defaultLocale : null;
|
||||
|
||||
if (!collection) {
|
||||
throw new APIError(`The collection with slug ${collectionSlug} can't be found.`);
|
||||
}
|
||||
|
||||
req.payloadAPI = 'local';
|
||||
req.locale = locale ?? req?.locale ?? defaultLocale;
|
||||
req.fallbackLocale = fallbackLocale ?? req?.fallbackLocale ?? defaultLocale;
|
||||
|
||||
@@ -6,6 +6,7 @@ import { PayloadRequest } from '../../../express/types';
|
||||
import findVersions from '../findVersions';
|
||||
import { getDataLoader } from '../../dataloader';
|
||||
import i18nInit from '../../../translations/init';
|
||||
import { APIError } from '../../../errors';
|
||||
|
||||
export type Options = {
|
||||
collection: string
|
||||
@@ -39,6 +40,10 @@ export default async function findVersionsLocal<T extends TypeWithVersion<T> = a
|
||||
const collection = payload.collections[collectionSlug];
|
||||
const defaultLocale = payload?.config?.localization ? payload?.config?.localization?.defaultLocale : null;
|
||||
|
||||
if (!collection) {
|
||||
throw new APIError(`The collection with slug ${collectionSlug} can't be found.`);
|
||||
}
|
||||
|
||||
const i18n = i18nInit(payload.config.i18n);
|
||||
const req = {
|
||||
user,
|
||||
|
||||
@@ -5,6 +5,7 @@ import { TypeWithVersion } from '../../../versions/types';
|
||||
import { getDataLoader } from '../../dataloader';
|
||||
import restoreVersion from '../restoreVersion';
|
||||
import i18nInit from '../../../translations/init';
|
||||
import { APIError } from '../../../errors';
|
||||
|
||||
export type Options = {
|
||||
collection: string
|
||||
@@ -30,6 +31,11 @@ export default async function restoreVersionLocal<T extends TypeWithVersion<T> =
|
||||
} = options;
|
||||
|
||||
const collection = payload.collections[collectionSlug];
|
||||
|
||||
if (!collection) {
|
||||
throw new APIError(`The collection with slug ${collectionSlug} can't be found.`);
|
||||
}
|
||||
|
||||
const i18n = i18nInit(payload.config.i18n);
|
||||
const req = {
|
||||
user,
|
||||
|
||||
@@ -6,6 +6,7 @@ import { PayloadRequest } from '../../../express/types';
|
||||
import { getDataLoader } from '../../dataloader';
|
||||
import { File } from '../../../uploads/types';
|
||||
import i18nInit from '../../../translations/init';
|
||||
import { APIError } from '../../../errors';
|
||||
|
||||
export type Options<T> = {
|
||||
collection: string
|
||||
@@ -43,6 +44,11 @@ export default async function updateLocal<T = any>(payload: Payload, options: Op
|
||||
} = options;
|
||||
|
||||
const collection = payload.collections[collectionSlug];
|
||||
|
||||
if (!collection) {
|
||||
throw new APIError(`The collection with slug ${collectionSlug} can't be found.`);
|
||||
}
|
||||
|
||||
const i18n = i18nInit(payload.config.i18n);
|
||||
const defaultLocale = payload.config.localization ? payload.config.localization?.defaultLocale : null;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Document } from '../../../types';
|
||||
import { TypeWithID } from '../../config/types';
|
||||
import findOne from '../findOne';
|
||||
import i18nInit from '../../../translations/init';
|
||||
import { APIError } from '../../../errors';
|
||||
|
||||
export type Options = {
|
||||
slug: string
|
||||
@@ -32,6 +33,11 @@ export default async function findOneLocal<T extends TypeWithID = any>(payload:
|
||||
const globalConfig = payload.globals.config.find((config) => config.slug === globalSlug);
|
||||
const i18n = i18nInit(payload.config.i18n);
|
||||
|
||||
|
||||
if (!globalConfig) {
|
||||
throw new APIError(`The global with slug ${globalSlug} can't be found.`);
|
||||
}
|
||||
|
||||
const req = {
|
||||
user,
|
||||
payloadAPI: 'local',
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Document } from '../../../types';
|
||||
import { TypeWithVersion } from '../../../versions/types';
|
||||
import findVersionByID from '../findVersionByID';
|
||||
import i18nInit from '../../../translations/init';
|
||||
import { APIError } from '../../../errors';
|
||||
|
||||
export type Options = {
|
||||
slug: string
|
||||
@@ -34,6 +35,10 @@ export default async function findVersionByIDLocal<T extends TypeWithVersion<T>
|
||||
const globalConfig = payload.globals.config.find((config) => config.slug === globalSlug);
|
||||
const i18n = i18nInit(payload.config.i18n);
|
||||
|
||||
if (!globalConfig) {
|
||||
throw new APIError(`The global with slug ${globalSlug} can't be found.`);
|
||||
}
|
||||
|
||||
const req = {
|
||||
user,
|
||||
payloadAPI: 'local',
|
||||
|
||||
@@ -6,6 +6,7 @@ import { PayloadRequest } from '../../../express/types';
|
||||
import findVersions from '../findVersions';
|
||||
import { getDataLoader } from '../../../collections/dataloader';
|
||||
import i18nInit from '../../../translations/init';
|
||||
import { APIError } from '../../../errors';
|
||||
|
||||
export type Options = {
|
||||
slug: string
|
||||
@@ -39,6 +40,10 @@ export default async function findVersionsLocal<T extends TypeWithVersion<T> = a
|
||||
const globalConfig = payload.globals.config.find((config) => config.slug === globalSlug);
|
||||
const i18n = i18nInit(payload.config.i18n);
|
||||
|
||||
if (!globalConfig) {
|
||||
throw new APIError(`The global with slug ${globalSlug} can't be found.`);
|
||||
}
|
||||
|
||||
const req = {
|
||||
user,
|
||||
payloadAPI: 'local',
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Document } from '../../../types';
|
||||
import { TypeWithVersion } from '../../../versions/types';
|
||||
import restoreVersion from '../restoreVersion';
|
||||
import i18nInit from '../../../translations/init';
|
||||
import { APIError } from '../../../errors';
|
||||
|
||||
export type Options = {
|
||||
slug: string
|
||||
@@ -32,6 +33,10 @@ export default async function restoreVersionLocal<T extends TypeWithVersion<T> =
|
||||
const globalConfig = payload.globals.config.find((config) => config.slug === globalSlug);
|
||||
const i18n = i18nInit(payload.config.i18n);
|
||||
|
||||
if (!globalConfig) {
|
||||
throw new APIError(`The global with slug ${globalSlug} can't be found.`);
|
||||
}
|
||||
|
||||
const req = {
|
||||
user,
|
||||
payloadAPI: 'local',
|
||||
|
||||
@@ -5,6 +5,7 @@ import { TypeWithID } from '../../config/types';
|
||||
import update from '../update';
|
||||
import { getDataLoader } from '../../../collections/dataloader';
|
||||
import i18nInit from '../../../translations/init';
|
||||
import { APIError } from '../../../errors';
|
||||
|
||||
export type Options = {
|
||||
slug: string
|
||||
@@ -34,6 +35,10 @@ export default async function updateLocal<T extends TypeWithID = any>(payload: P
|
||||
const globalConfig = payload.globals.config.find((config) => config.slug === globalSlug);
|
||||
const i18n = i18nInit(payload.config.i18n);
|
||||
|
||||
if (!globalConfig) {
|
||||
throw new APIError(`The global with slug ${globalSlug} can't be found.`);
|
||||
}
|
||||
|
||||
const req = {
|
||||
user,
|
||||
payloadAPI: 'local',
|
||||
|
||||
Reference in New Issue
Block a user