Class ErrorMessage (3.0.4)

Package

@google-cloud/error-reporting

Constructors

(constructor)()

constructor();

The constructor for ErrorMessage takes no arguments and is solely meant to to instantiate properties on the instance. Each property should be externally set using the corresponding set function with the exception of eventTime which can be set externally but does not need to be since it is inited to an ISO-8601 compliant time string. {Object} ErrorMessage ErrorMessage is a class which is meant to store and control-for Google Cloud Error API submittable values. Meant to be JSON string-ifiable representation of the final values which will be submitted to the Error API this class enforces type-checking on every setter function and will write default type-friendly values to instance properties if given values which are type-incompatible to expectations. These type-friendly default substitutions will occur silently and no errors will be thrown on attempted invalid input under the premise that during misassignment some error information sent to the Error API is better than no error information due to the Error library failing under invalid input. {String} eventTime - an ISO-8601 compliant string representing when the error was created {Object} serviceContext - The service information for the error {String} serviceContext.service - The service that the error was was produced on {String|Undefined} serviceContext.version - The service version that the error was produced on {String} message - The error message {Object} context - the request, user and report context {Object} context.httpRequest - the request context {String} context.httpRequest.method - the request method (e.g. GET) {String} context.httpRequest.url - the request url or path {String} context.httpRequest.userAgent - the requesting user-agent {String} context.httpRequest.referrer - the request referrer {Number} context.httpRequest.responseStatusCode - the request status-code {String} context.httpRequest.remoteIp - the requesting remote ip {String} context.user - the vm instances user {Object} context.reportLocation - the report context {String} context.reportLocation.filePath - the file path of the report site {Number} context.reportLocation.lineNumber - the line number of the report site {String} context.reportLocation.functionName - the function name of the report site

Properties

context

context: Context;

eventTime

eventTime: string;

message

message: string;

serviceContext

serviceContext: ServiceContext;

Methods

consumeRequestInformation(requestInformation)

consumeRequestInformation(requestInformation: RequestInformationContainer): this;

Consumes the standard object created by the requestInformationExtractors and assigns the properties of the object onto the instance.

Parameter
NameDescription
requestInformation RequestInformationContainer

the standardized object created by the information extractors

Returns
TypeDescription
this

{this} - returns the instance for chaining

setEventTimeToNow()

setEventTimeToNow(): this;

Sets the eventTime property on the instance to an ISO-8601 compliant string representing the current time at invocation. setEventTimeToNow

Returns
TypeDescription
this

{this} - returns the instance for chaining

setFilePath(filePath)

setFilePath(filePath?: string): this;

Sets the context.reportLocation.filePath property on the instance

Parameter
NameDescription
filePath string

the vm instances filePath

Returns
TypeDescription
this

{this} - returns the instance for chaining

setFunctionName(functionName)

setFunctionName(functionName?: string): this;

Sets the context.reportLocation.functionName property on the instance

Parameter
NameDescription
functionName string

the function name of the report context

Returns
TypeDescription
this

{this} - returns the instance for chaining

setHttpMethod(method)

setHttpMethod(method?: string): this;

Sets the context.httpRequest.method property on the instance.

Parameter
NameDescription
method string

the HTTP method on the request which caused the errors instantiation

Returns
TypeDescription
this

{this} - returns the instance for chaining

setLineNumber(lineNumber)

setLineNumber(lineNumber?: number): this;

Sets the context.reportLocation.lineNumber property on the instance

Parameter
NameDescription
lineNumber number

the line number of the report context

Returns
TypeDescription
this

{this} - returns the instance for chaining

setMessage(message)

setMessage(message?: string): this;

Sets the message property on the instance.

Parameter
NameDescription
message string

the error message

Returns
TypeDescription
this

{this} - returns the instance for chaining

setReferrer(referrer)

setReferrer(referrer?: string): this;

Sets the context.httpRequest.referrer property on the instance.

Parameter
NameDescription
referrer string

the requests referrer

Returns
TypeDescription
this

{this} - returns the instance for chaining

setRemoteIp(remoteIp)

setRemoteIp(remoteIp?: string): this;

Sets the context.httpRequest.remoteIp property on the instance

Parameter
NameDescription
remoteIp string

the requesters remote IP

Returns
TypeDescription
this

{this} - returns the instance for chaining

setResponseStatusCode(responseStatusCode)

setResponseStatusCode(responseStatusCode?: number): this;

Sets the context.httpRequest.responseStatusCode property on the instance.

Parameter
NameDescription
responseStatusCode number

the response status code

Returns
TypeDescription
this

{this} - returns the instance for chaining

setServiceContext(service, version)

setServiceContext(service?: string, version?: string): this;

Sets the serviceContext property on the instance and its two constituent properties: service and version. setServiceContext

Parameters
NameDescription
service string

the service the error was reported on

version string

the version the service was on when the error was reported

Returns
TypeDescription
this

{this} - returns the instance for chaining

setUrl(url)

setUrl(url?: string): this;

Sets the context.httpRequest.url property on the instance.

Parameter
NameDescription
url string

the requests target url

Returns
TypeDescription
this

{this} - returns the instance for chaining

setUser(user)

setUser(user?: string): this;

Sets the context.user property on the instance

Parameter
NameDescription
user string

the vm instances user

Returns
TypeDescription
this

{this} - returns the instance for chaining

setUserAgent(userAgent)

setUserAgent(userAgent?: string): this;

Sets the context.httpRequest.userAgent property on the instance.

Parameter
NameDescription
userAgent string

the requests user-agent

Returns
TypeDescription
this

{this} - returns the instance for chaining