diff options
Diffstat (limited to 'server/helpers/requests.ts')
-rw-r--r-- | server/helpers/requests.ts | 18 |
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 @@ | |||
1 | import { createWriteStream, remove } from 'fs-extra' | 1 | import { createWriteStream, remove } from 'fs-extra' |
2 | import got, { CancelableRequest, Options as GotOptions } from 'got' | 2 | import got, { CancelableRequest, Options as GotOptions, RequestError } from 'got' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { CONFIG } from '../initializers/config' | 4 | import { CONFIG } from '../initializers/config' |
5 | import { ACTIVITY_PUB, PEERTUBE_VERSION, WEBSERVER } from '../initializers/constants' | 5 | import { ACTIVITY_PUB, PEERTUBE_VERSION, WEBSERVER } from '../initializers/constants' |
@@ -7,6 +7,11 @@ import { pipelinePromise } from './core-utils' | |||
7 | import { processImage } from './image-utils' | 7 | import { processImage } from './image-utils' |
8 | import { logger } from './logger' | 8 | import { logger } from './logger' |
9 | 9 | ||
10 | export interface PeerTubeRequestError extends Error { | ||
11 | statusCode?: number | ||
12 | responseBody?: any | ||
13 | } | ||
14 | |||
10 | const httpSignature = require('http-signature') | 15 | const httpSignature = require('http-signature') |
11 | 16 | ||
12 | type PeerTubeRequestOptions = { | 17 | type PeerTubeRequestOptions = { |
@@ -180,14 +185,15 @@ function buildGotOptions (options: PeerTubeRequestOptions) { | |||
180 | } | 185 | } |
181 | } | 186 | } |
182 | 187 | ||
183 | function buildRequestError (error: any) { | 188 | function 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 | } |