Skip to content

Commit 15093f7

Browse files
committed
feat(accounts): [errors]: InvalidCredentialException
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent ab27540 commit 15093f7

File tree

4 files changed

+121
-0
lines changed

4 files changed

+121
-0
lines changed

src/errors/enums/exception-id.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
enum ExceptionId {
1212
EMAIL_CONFLICT = 'accounts/email-conflict',
1313
INTERNAL_SERVER_ERROR = 'sneusers/internal-error',
14+
INVALID_CREDENTIAL = 'accounts/invalid-credential',
1415
VALIDATION_FAILURE = 'sneusers/validation-failure'
1516
}
1617

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* @file Unit Tests - InvalidCredentialException
3+
* @module sneusers/accounts/errors/tests/unit/InvalidCredentialException
4+
*/
5+
6+
import TestSubject from '#accounts/errors/invalid-credential.exception'
7+
import ExceptionCode from '#errors/enums/exception-code'
8+
import ExceptionId from '#errors/enums/exception-id'
9+
import Exception from '#errors/models/base.exception'
10+
11+
describe('unit:accounts/errors/InvalidCredentialException', () => {
12+
describe('constructor', () => {
13+
let subject: TestSubject
14+
15+
beforeAll(() => {
16+
subject = new TestSubject()
17+
})
18+
19+
it('should be instanceof Exception', () => {
20+
expect(subject).to.be.instanceof(Exception)
21+
})
22+
23+
it('should set #cause', () => {
24+
expect(subject).to.have.property('cause', null)
25+
})
26+
27+
it('should set #code', () => {
28+
expect(subject).to.have.property('code', ExceptionCode.UNAUTHORIZED)
29+
})
30+
31+
it('should set #id', () => {
32+
expect(subject).to.have.property('id', ExceptionId.INVALID_CREDENTIAL)
33+
})
34+
35+
it('should set #message', () => {
36+
expect(subject).to.have.property('message', 'Invalid credential')
37+
})
38+
39+
it('should set #name', () => {
40+
expect(subject).to.have.property('name', TestSubject.name)
41+
})
42+
43+
it('should set #reason', () => {
44+
expect(subject).to.have.property('reason', null)
45+
})
46+
47+
it('should set #stack', () => {
48+
expect(subject).to.have.property('stack').be.a('string').that.is.not.empty
49+
})
50+
})
51+
})

src/subdomains/accounts/errors/index.mts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
export {
77
default as EmailConflictException
88
} from '#accounts/errors/email-conflict.exception'
9+
export {
10+
default as InvalidCredentialException
11+
} from '#accounts/errors/invalid-credential.exception'
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* @file Errors - InvalidCredentialException
3+
* @module sneusers/accounts/errors/InvalidCredentialException
4+
*/
5+
6+
import {
7+
Exception,
8+
ExceptionCode,
9+
ExceptionId
10+
} from '@flex-development/sneusers/errors'
11+
import { ApiProperty, ApiSchema } from '@nestjs/swagger'
12+
13+
/**
14+
* An invalid credential exception.
15+
*
16+
* @class
17+
* @extends {Exception}
18+
*/
19+
@ApiSchema()
20+
class InvalidCredentialException extends Exception {
21+
/**
22+
* HTTP response status code.
23+
*
24+
* @public
25+
* @instance
26+
* @member {ExceptionCode.UNAUTHORIZED} code
27+
*/
28+
@ApiProperty({ enum: [ExceptionCode.UNAUTHORIZED] })
29+
declare public code: (typeof ExceptionCode)['UNAUTHORIZED']
30+
31+
/**
32+
* Unique id representing the exception.
33+
*
34+
* @public
35+
* @instance
36+
* @member {ExceptionId.INVALID_CREDENTIAL} code
37+
*/
38+
@ApiProperty({ enum: [ExceptionId.INVALID_CREDENTIAL] })
39+
declare public id: (typeof ExceptionId)['INVALID_CREDENTIAL']
40+
41+
/**
42+
* The reason for the exception.
43+
*
44+
* @public
45+
* @instance
46+
* @member {null} reason
47+
*/
48+
@ApiProperty({ type: 'null' })
49+
declare public reason: null
50+
51+
/**
52+
* Create a new invalid credential exception.
53+
*/
54+
constructor() {
55+
super({
56+
code: ExceptionCode.UNAUTHORIZED,
57+
id: ExceptionId.INVALID_CREDENTIAL,
58+
message: 'Invalid credential',
59+
reason: null
60+
})
61+
62+
this.name = 'InvalidCredentialException'
63+
}
64+
}
65+
66+
export default InvalidCredentialException

0 commit comments

Comments
 (0)