-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
79 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
import { Severity } from '@sentry/react'; | ||
import { saveAs } from 'file-saver'; | ||
|
||
const errorLogs: { meta: any; error: any }[] = []; | ||
import * as Sentry from '@sentry/react'; | ||
import { TxCandidate } from '@spectrumlabs/cardano-dex-sdk'; | ||
|
||
interface OperationError { | ||
readonly level: Severity; | ||
readonly error: Error; | ||
} | ||
|
||
const jsonReplacer = (_, value) => | ||
typeof value === 'bigint' ? value.toString() : value; | ||
|
||
export const captureOperationError = ( | ||
error: Error | string, | ||
network: 'cardano' | 'ergo', | ||
operation: string, | ||
candidate?: TxCandidate, | ||
context?: object, | ||
): void => { | ||
const message = typeof error === 'string' ? error : error.message; | ||
|
||
Sentry.captureMessage(message, { | ||
level: Severity.Critical, | ||
extra: { | ||
candidate: candidate | ||
? JSON.stringify(candidate, jsonReplacer, 2) | ||
: undefined, | ||
context: context ? JSON.stringify(context, jsonReplacer, 2) : undefined, | ||
network, | ||
operation, | ||
}, | ||
}); | ||
}; | ||
|
||
export const toSentryOperationError = ( | ||
error: Error | string, | ||
): OperationError => ({ | ||
level: Severity.Critical, | ||
error: typeof error === 'string' ? new Error(error as string) : error, | ||
}); | ||
|
||
export const addErrorLog = | ||
(meta: any) => | ||
(error: Error): void => { | ||
errorLogs.push({ meta, error: error?.message || error }); | ||
}; | ||
|
||
export const downloadErrorLog = () => { | ||
saveAs( | ||
new Blob( | ||
[ | ||
JSON.stringify( | ||
errorLogs, | ||
(_, value) => (typeof value === 'bigint' ? value.toString() : value), | ||
2, | ||
), | ||
], | ||
{ | ||
type: 'text/plain;charset=utf-8', | ||
}, | ||
), | ||
'logs.txt', | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters