Skip to content

Commit

Permalink
chore: cleanup after branch update
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasheartman committed May 5, 2023
1 parent f911ae7 commit 259bf11
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
2 changes: 0 additions & 2 deletions src/lib/error/api-error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,6 @@ describe('Error serialization special cases', () => {
});
});

// test that password mismatch errors contain the expected props etc. ...

describe('Error serialization special cases', () => {
it('AuthenticationRequired: adds `path` and `type`', () => {
const type = 'password';
Expand Down
8 changes: 1 addition & 7 deletions src/lib/error/api-error.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { v4 as uuidV4 } from 'uuid';
import { FromSchema } from 'json-schema-to-ts';
import { ErrorObject } from 'ajv';
import OwaspValidationError from './owasp-validation-error';

export const UnleashApiErrorTypes = [
Expand Down Expand Up @@ -232,12 +231,7 @@ export const fromLegacyError = (e: Error): UnleashError => {
}

if (name === 'OwaspValidationError') {
return new UnleashError({
name,
message:
'Password validation failed. Refer to the `details` property.',
details: (e as OwaspValidationError).toJSON().details,
});
return e as OwaspValidationError;
}

if (name === 'AuthenticationRequired') {
Expand Down
21 changes: 12 additions & 9 deletions src/lib/error/owasp-validation-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,29 @@ import { TestResult } from 'owasp-password-strength-test';
import { ApiErrorSchema, UnleashError } from './api-error';

class OwaspValidationError extends UnleashError {
private errors: string[];
private details: [
{ validationErrors: string[]; message: string },
...{ validationErrors: string[]; message: string }[],
];

constructor(testResult: TestResult) {
const details = {
validationErrors: testResult.errors,
message: testResult.errors[0],
};
super({
message: testResult.errors[0],
name: 'OwaspValidationError',
details: [details],
});
this.errors = testResult.errors;

this.details = [details];
}

toJSON(): ApiErrorSchema {
return {
...super.toJSON(),
details: [
{
validationErrors: this.errors,
message: this.errors[0],
description: this.errors[0],
},
],
details: this.details,
};
}
}
Expand Down

0 comments on commit 259bf11

Please sign in to comment.