diff options
author | Chocobozzz <me@florianbigard.com> | 2021-03-09 14:01:44 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-03-24 18:18:40 +0100 |
commit | b5c361089f03f4d459fa1cdc49ff66dee736af12 (patch) | |
tree | 0ac886c8358e890dc45b3e53f7b0da2e1c979122 /server/helpers/requests.ts | |
parent | 2d5a469427641e5ace48ad487bae2f35d9759107 (diff) | |
download | PeerTube-b5c361089f03f4d459fa1cdc49ff66dee736af12.tar.gz PeerTube-b5c361089f03f4d459fa1cdc49ff66dee736af12.tar.zst PeerTube-b5c361089f03f4d459fa1cdc49ff66dee736af12.zip |
Fix 404 AP status codes
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 | } |