Skip to content

Commit

Permalink
Put ajv error in statusText
Browse files Browse the repository at this point in the history
  • Loading branch information
enjikaka committed Jan 10, 2024
1 parent bf0a88a commit 70cc559
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class Rutabaga {
*/
#openDatabase() {
if (!this.#dataBaseName) {
throw new Error("No data base name provided in the construvtor");
throw new Error("No data base name provided in the constructor");
}

return new Dexie(this.#dataBaseName);
Expand Down Expand Up @@ -80,7 +80,7 @@ export class Rutabaga {
if (!this.validate(obj)) {
return new Response(null, {
status: httpStatusCodes.BAD_REQUEST,
statusText: `The provided form data did not validate against the schema "${this.#schemaName}". ${JSON.stringify(this.#schema)}`
statusText: `The provided form data did not validate against the schema "${this.#schemaName}". Reason: ${JSON.stringify(this.#validate.errors)}`
});
}

Expand Down
1 change: 1 addition & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ describe('handlePost', () => {
const response = await rutabaga.handlePost(request);

expect(response.status).toBe(402);
expect(response.statusText).toBe('The provided form data did not validate against the schema "person". Reason: [{"instancePath":"","schemaPath":"#/additionalProperties","keyword":"additionalProperties","params":{"additionalProperty":"middleName"},"message":"must NOT have additional properties"}]');
});

test("returns 201 if form data is accepted and added to the database", async () => {
Expand Down

0 comments on commit 70cc559

Please sign in to comment.