Skip to content

Commit

Permalink
ErrorUtils: Passing Error objects in test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamkmr04 committed Mar 26, 2024
1 parent a19cae5 commit 41090ab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions utils/ErrorUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@ describe('ErrorUtils', () => {
it('Turns error message to user friendly values', () => {
expect(
errorToUserFriendly(
{
Object.assign(new Error(), {
message: `{
"code": 2,
"message": "transaction output is dust",
"details": []
}`,
name: 'test'
},
}),
false
)
).toEqual('transaction output is dust');
expect(
errorToUserFriendly(
{
Object.assign(new Error(), {
message: `{
"code": 2,
"message": "proto: (line 1:126): invalid value for uint64 type: 0.1",
"details": []
}`,
name: 'test'
},
}),
false
)
).toEqual(
'proto: (line 1:126): invalid value for uint64 type: 0.1'
);
expect(
errorToUserFriendly(
{
Object.assign(new Error(), {
message: `{
"error": {
"code": 2,
Expand All @@ -43,13 +43,13 @@ describe('ErrorUtils', () => {
}
`,
name: 'test'
},
}),
false
)
).toEqual('invoice is already paid');
expect(
errorToUserFriendly(
{
Object.assign(new Error(), {
message: `{
"error": {
"code": 2,
Expand All @@ -59,31 +59,31 @@ describe('ErrorUtils', () => {
}
`,
name: 'test'
},
}),
false
)
).toEqual(
'Host unreachable. Try restarting your node or its Tor process.'
);
expect(
errorToUserFriendly(
{
Object.assign(new Error(), {
message:
'Error: called `Result::unwrap()` on an `Err` value: BootStrapError("Timeout waiting for bootstrap")',
name: 'test'
},
}),
false
)
).toEqual(
'Error starting up Tor on your phone. Try restarting Zeus. If the problem persists consider using the Orbot app to connect to Tor, or using an alternative connection method like Lightning Node Connect or Tailscale.'
);
expect(
errorToUserFriendly(
{
Object.assign(new Error(), {
message:
'Error: called `Result::unwrap()` on an `Err` value: BootStrapError("Timeout waiting for boostrap")',
name: 'test'
},
}),
false
)
).toEqual(
Expand All @@ -94,10 +94,10 @@ describe('ErrorUtils', () => {
it('Returns inputted error if no match found', () => {
expect(
errorToUserFriendly(
{
Object.assign(new Error(), {
message: 'Random message',
name: 'test'
},
}),
false
)
).toEqual('Random message');
Expand Down
2 changes: 1 addition & 1 deletion utils/ErrorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const userFriendlyErrors: any = {
};

const errorToUserFriendly = (error: Error, localize = true) => {
let errorMessage: object | string | any = error.message;
let errorMessage: string = error.message;
let errorObject: any;

try {
Expand Down

0 comments on commit 41090ab

Please sign in to comment.