do not fail when webhook endpoint doesn't exist
This commit is contained in:
		@@ -1,11 +1,15 @@
 | 
				
			|||||||
export async function webhookUserReported(endpoint: string, uuid: string) {
 | 
					export async function webhookUserReported(endpoint: string, uuid: string) {
 | 
				
			||||||
	await fetch(endpoint, {
 | 
						try {
 | 
				
			||||||
		method: 'POST',
 | 
							await fetch(endpoint, {
 | 
				
			||||||
		headers: {
 | 
								method: 'POST',
 | 
				
			||||||
			'Content-Type': 'application/json'
 | 
								headers: {
 | 
				
			||||||
		},
 | 
									'Content-Type': 'application/json'
 | 
				
			||||||
		body: JSON.stringify({
 | 
								},
 | 
				
			||||||
			user: uuid
 | 
								body: JSON.stringify({
 | 
				
			||||||
		})
 | 
									user: uuid
 | 
				
			||||||
	});
 | 
								})
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
						} catch (e) {
 | 
				
			||||||
 | 
							throw (e as { message: string }).message;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -153,8 +153,12 @@ export const PATCH = (async ({ request, cookies }) => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if (webhookTriggerUsers.length > 0 && data.status == 'reviewed' && env.REPORTED_WEBHOOK) {
 | 
						if (webhookTriggerUsers.length > 0 && data.status == 'reviewed' && env.REPORTED_WEBHOOK) {
 | 
				
			||||||
		for (const webhookTriggerUser of webhookTriggerUsers) {
 | 
							for (const webhookTriggerUser of webhookTriggerUsers) {
 | 
				
			||||||
			// no `await` to avoid blocking
 | 
								try {
 | 
				
			||||||
			webhookUserReported(env.REPORTED_WEBHOOK, webhookTriggerUser);
 | 
									// no `await` to avoid blocking
 | 
				
			||||||
 | 
									webhookUserReported(env.REPORTED_WEBHOOK, webhookTriggerUser);
 | 
				
			||||||
 | 
								} catch (e) {
 | 
				
			||||||
 | 
									console.error(`failed to send reported webhook: ${e}`);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user