aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/requests.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/requests.ts')
-rw-r--r--server/helpers/requests.ts18
1 files changed, 12 insertions, 6 deletions
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts
index aee8f6673..5eb69486d 100644
--- a/server/helpers/requests.ts
+++ b/server/helpers/requests.ts
@@ -1,5 +1,5 @@
1import { createWriteStream, remove } from 'fs-extra' 1import { createWriteStream, remove } from 'fs-extra'
2import got, { CancelableRequest, Options as GotOptions } from 'got' 2import got, { CancelableRequest, Options as GotOptions, RequestError } from 'got'
3import { join } from 'path' 3import { join } from 'path'
4import { CONFIG } from '../initializers/config' 4import { CONFIG } from '../initializers/config'
5import { ACTIVITY_PUB, PEERTUBE_VERSION, WEBSERVER } from '../initializers/constants' 5import { ACTIVITY_PUB, PEERTUBE_VERSION, WEBSERVER } from '../initializers/constants'
@@ -7,6 +7,11 @@ import { pipelinePromise } from './core-utils'
7import { processImage } from './image-utils' 7import { processImage } from './image-utils'
8import { logger } from './logger' 8import { logger } from './logger'
9 9
10export interface PeerTubeRequestError extends Error {
11 statusCode?: number
12 responseBody?: any
13}
14
10const httpSignature = require('http-signature') 15const httpSignature = require('http-signature')
11 16
12type PeerTubeRequestOptions = { 17type PeerTubeRequestOptions = {
@@ -180,14 +185,15 @@ function buildGotOptions (options: PeerTubeRequestOptions) {
180 } 185 }
181} 186}
182 187
183function buildRequestError (error: any) { 188function buildRequestError (error: RequestError) {
184 const newError = new Error(error.message) 189 const newError: PeerTubeRequestError = new Error(error.message)
185 newError.name = error.name 190 newError.name = error.name
186 newError.stack = error.stack 191 newError.stack = error.stack
187 192
188 if (error.response?.body) { 193 if (error.response) {
189 error.responseBody = error.response.body 194 newError.responseBody = error.response.body
195 newError.statusCode = error.response.statusCode
190 } 196 }
191 197
192 return error 198 return newError
193} 199}