Skip to content

Commit

Permalink
Improve error reporting (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospassos authored Nov 13, 2024
1 parent c45f586 commit 7e225ac
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/server/evaluate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ describe('evaluation', () => {
});

await expect(evaluate('true')).rejects.toThrow(
'evaluate() requires specifying the `route` option outside app routes. '
'Error resolving request context: next/headers requires app router. '
+ 'This error usually occurs when no `route` option is specified when evaluate() '
+ 'is called outside of app routes. '
+ 'For help, see: https://croct.help/sdk/nextjs/missing-route-context',
);
});
Expand Down
5 changes: 4 additions & 1 deletion src/server/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {evaluate as executeQuery, EvaluationOptions as BaseOptions} from '@croct
import type {JsonValue} from '@croct/plug-react';
import {FilteredLogger} from '@croct/sdk/logging/filteredLogger';
import {ConsoleLogger} from '@croct/sdk/logging/consoleLogger';
import {formatCause} from '@croct/sdk/error';
import {getApiKey} from '@/config/security';
import {RequestContext, resolveRequestContext} from '@/config/context';
import {getDefaultFetchTimeout} from '@/config/timeout';
Expand All @@ -23,7 +24,9 @@ export function evaluate<T extends JsonValue>(query: string, options: Evaluation
if (route === undefined) {
return Promise.reject(
new Error(
'evaluate() requires specifying the `route` option outside app routes. '
`Error resolving request context: ${formatCause(error)}. `
+ 'This error usually occurs when no `route` option is specified when evaluate() '
+ 'is called outside of app routes. '
+ 'For help, see: https://croct.help/sdk/nextjs/missing-route-context',
),
);
Expand Down
4 changes: 3 additions & 1 deletion src/server/fetchContent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ describe('fetchContent', () => {
});

await expect(fetchContent('slot-id')).rejects.toThrow(
'fetchContent() requires specifying the `route` option outside app routes. '
'Error resolving request context: next/headers requires app router. '
+ 'This error usually occurs when no `route` option is specified when fetchContent() '
+ 'is called outside of app routes. '
+ 'For help, see: https://croct.help/sdk/nextjs/missing-route-context',
);
});
Expand Down
5 changes: 4 additions & 1 deletion src/server/fetchContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import type {SlotContent, VersionedSlotId, JsonObject} from '@croct/plug-react';
import {FilteredLogger} from '@croct/sdk/logging/filteredLogger';
import {ConsoleLogger} from '@croct/sdk/logging/consoleLogger';
import {formatCause} from '@croct/sdk/error';
import {getApiKey} from '@/config/security';
import {RequestContext, resolvePreferredLocale, resolveRequestContext} from '@/config/context';
import {getDefaultFetchTimeout} from '@/config/timeout';
Expand Down Expand Up @@ -65,7 +66,9 @@ export function fetchContent<I extends VersionedSlotId, C extends JsonObject>(
if (route === undefined) {
return Promise.reject(
new Error(
'fetchContent() requires specifying the `route` option outside app routes. '
`Error resolving request context: ${formatCause(error)}. `
+ 'This error usually occurs when no `route` option is specified when fetchContent() '
+ 'is called outside of app routes. '
+ 'For help, see: https://croct.help/sdk/nextjs/missing-route-context',
),
);
Expand Down

0 comments on commit 7e225ac

Please sign in to comment.