-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from vtexdocs/logs
adding error logs
- Loading branch information
Showing
7 changed files
with
125 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// sendLog sends a message to the slack channel #docs-in-tickets-logs. | ||
// ref: https://api.slack.com/messaging/webhooks | ||
|
||
import { ExternalClient } from '@vtex/api' | ||
import type { IOContext, InstanceOptions } from '@vtex/api' | ||
|
||
const url = 'https://hooks.slack.com/services/xxxxxxxxxx' | ||
const requestHeaders = { | ||
'Content-Type': 'application/json', | ||
} | ||
|
||
export default class SlackClient extends ExternalClient { | ||
constructor(ctx: IOContext, options?: InstanceOptions) { | ||
super('https://hooks.slack.com', ctx, { | ||
...options, | ||
retries: 2, | ||
timeout: 2000, | ||
headers: requestHeaders, | ||
}) | ||
} | ||
|
||
public async sendLog(log: string, type: string) { | ||
|
||
const logTypeMap: { [key: string]: string} = { | ||
info: ':ms_information_3d:', | ||
warning: ':warning: *Warning*', | ||
error: ':error: *Error*' | ||
} | ||
const typeMarker = logTypeMap[type] || '' | ||
|
||
return this.http.post( | ||
url, | ||
{ | ||
text: `${typeMarker}\n${log}` | ||
}, | ||
{ | ||
headers: requestHeaders, | ||
} | ||
) | ||
} | ||
} |
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,18 @@ | ||
// Returning and logging errors | ||
|
||
export async function returnError( | ||
zendeskTicket: string, | ||
status: number, | ||
errorMessage: string, | ||
ctx: Context | ||
) { | ||
|
||
const slack = ctx.clients.slack | ||
slack.sendLog(`ticket: ${zendeskTicket}\n${errorMessage}`, 'error') | ||
|
||
ctx.status = status | ||
ctx.response.body = { | ||
ticketId: zendeskTicket, | ||
message: errorMessage | ||
} | ||
} |
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