-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow publishing of empty message (#724)
* feat: allow publishing of empty message * feat: improve publishing error message for incorrect headers + bindings
- Loading branch information
Showing
9 changed files
with
106 additions
and
64 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
class ApplicationError extends Error {} | ||
|
||
export function wrapException<T>(message: string, f: () => T): T { | ||
try { | ||
return f(); | ||
} catch (e) { | ||
if (e instanceof Error) { | ||
throw new ApplicationError(message + " (" + e.message + ")"); | ||
} | ||
throw new ApplicationError(message + " (" + e + ")"); | ||
} | ||
} | ||
|
||
export function catchException<T>( | ||
f: () => T, | ||
errorHandler: (e: any) => void = () => {} | ||
): T | undefined { | ||
try { | ||
return f(); | ||
} catch (e) { | ||
if (errorHandler !== undefined) { | ||
errorHandler(e); | ||
} | ||
|
||
return undefined; | ||
} | ||
} |