Skip to content

Commit ba7d8b0

Browse files
freelerobotBenjamin E. Coe
andauthored
fix: convert AdditionalMessage param into string type CustomMessage (#535)
* fix: convert AdditionalMessage into string only customMessage * docs: clarify customMessage param is intended to override stack trace Co-authored-by: Benjamin E. Coe <bencoe@google.com>
1 parent ae63f68 commit ba7d8b0

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class ErrorReporting {
109109
// eslint-disable-next-line @typescript-eslint/no-explicit-any
110110
err: any,
111111
request?: manualRequestExtractor.Request,
112-
additionalMessage?: string | {},
112+
customMessage?: string,
113113
callback?: manualInterface.Callback | {} | string
114114
) => ErrorMessage;
115115
event!: () => ErrorMessage;

src/interfaces/manual.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ export function handlerSetup(
5555
* application code.
5656
* @param {Any|ErrorMessage} err - error information of any type or content.
5757
* This can be of any type but by giving an instance of ErrorMessage as the
58-
* error arugment one can manually provide values to all fields of the
58+
* error argument one can manually provide values to all fields of the
5959
* potential payload.
6060
* @param {Object} [request] - an object containing request information. This
6161
* is expected to be an object similar to the Node/Express request object.
62-
* @param {String} [additionalMessage] - a string containing error message
63-
* information to override the builtin message given by an Error/Exception
62+
* @param {String} [customMessage] - an optional error message string that
63+
* overrides the default message & stack trace. Message format must comply
64+
* with message field requirements defined in the documentation:
65+
* https://cloud.google.com/error-reporting/reference/rest/v1beta1/projects.events/report#reportederrorevent
6466
* @param {Function} [callback] - a callback to be invoked once the message
6567
* has been successfully submitted to the error reporting API or has failed
6668
* after four attempts with the success or error response.
@@ -71,7 +73,7 @@ export function handlerSetup(
7173
function reportManualError(err: AnyError, request: Request): ErrorMessage;
7274
function reportManualError(
7375
err: AnyError,
74-
additionalMessage: string
76+
customMessage: string
7577
): ErrorMessage;
7678
function reportManualError(err: AnyError, callback: Callback): ErrorMessage;
7779
function reportManualError(
@@ -82,41 +84,41 @@ export function handlerSetup(
8284
function reportManualError(
8385
err: AnyError,
8486
request: Request,
85-
additionalMessage: string
87+
customMessage: string
8688
): ErrorMessage;
8789
function reportManualError(
8890
err: AnyError,
89-
additionalMessage: string,
91+
customMessage: string,
9092
callback: Callback
9193
): ErrorMessage;
9294
function reportManualError(
9395
err: AnyError,
9496
request: Request,
95-
additionalMessage: string,
97+
customMessage: string,
9698
callback: Callback
9799
): ErrorMessage;
98100
function reportManualError(
99101
err: AnyError,
100102
request?: Request | Callback | string,
101-
additionalMessage?: Callback | string | {},
103+
customMessage?: Callback | string,
102104
callback?: Callback | {} | string
103105
): ErrorMessage {
104106
let em;
105107
if (is.string(request)) {
106108
// no request given
107-
callback = additionalMessage;
108-
additionalMessage = request;
109+
callback = customMessage;
110+
customMessage = request as string;
109111
request = undefined;
110112
} else if (is.function(request)) {
111-
// neither request nor additionalMessage given
113+
// neither request nor customMessage given
112114
callback = request;
113115
request = undefined;
114-
additionalMessage = undefined;
116+
customMessage = undefined;
115117
}
116118

117-
if (is.function(additionalMessage)) {
118-
callback = additionalMessage;
119-
additionalMessage = undefined;
119+
if (is.function(customMessage)) {
120+
callback = customMessage;
121+
customMessage = undefined;
120122
}
121123

122124
if (err instanceof ErrorMessage) {
@@ -157,8 +159,8 @@ export function handlerSetup(
157159
);
158160
}
159161

160-
if (is.string(additionalMessage)) {
161-
em.setMessage(additionalMessage as string);
162+
if (is.string(customMessage)) {
163+
em.setMessage(customMessage as string);
162164
}
163165

164166
// TODO: Address this type cast

test/unit/interfaces/manual.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('Manual handler', () => {
4343
warn(message: string) {
4444
// The use of `report` in this class should issue the following
4545
// warning becasue the `report` class is used directly and, as such,
46-
// cannot by itself have information where a ErrorMesasge was
46+
// cannot by itself have information where a ErrorMessage was
4747
// constructed. It only knows that an error has been reported. Thus,
4848
// the ErrorMessage objects given to the `report` method in the tests
4949
// do not have construction site information to verify that if that

0 commit comments

Comments
 (0)