Skip to content

Commit

Permalink
Merge branch 'main' into DEV-1469-reset-signup-form-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremygordillo authored Mar 22, 2024
2 parents a6b9d8b + 97d1679 commit cba5663
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-buses-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nextjs-website": patch
---

[DEV-1545] Add custom PathReporter to improve readability of errors raised by decode
14 changes: 14 additions & 0 deletions apps/nextjs-website/src/lib/strapi/PathReporter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as t from 'io-ts';

const getMessage = (error: t.ValidationError): string => {
if (error.message) {
return error.message;
} else {
const jsonPath = error.context.map(({ key }) => `${key}`).join('/');
const expected = error.context[error.context.length - 1].type.name;
return `Invalid value ${error.value} supplied to '${jsonPath}', expected type ${expected}`;
}
};

export const failure = (errors: t.Errors): ReadonlyArray<string> =>
errors.map(getMessage);
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('fetchFromStrapi', () => {
});
const actual = fetchFromStrapi('aPath', 'aPopulate', badCodec)(env);
const expected = new Error(
'Invalid value 1 supplied to : {| data: {| id: string |} |}/data: {| id: string |}/id: string'
`Invalid value 1 supplied to '/data/id', expected type string`
);
await expect(actual).rejects.toStrictEqual(expected);
});
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs-website/src/lib/strapi/fetchFromStrapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { pipe } from 'fp-ts/lib/function';
import * as R from 'fp-ts/lib/Reader';
import * as E from 'fp-ts/lib/Either';
import * as TE from 'fp-ts/lib/TaskEither';
import * as PR from 'io-ts/lib/PathReporter';
import * as PR from './PathReporter';
import { StrapiEnv } from '@/lib/strapi/StapiEnv';

// Function to invoke in order to retrieve data from Strapi.
Expand Down

0 comments on commit cba5663

Please sign in to comment.