From b5c361089f03f4d459fa1cdc49ff66dee736af12 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 9 Mar 2021 14:01:44 +0100 Subject: Fix 404 AP status codes --- server/helpers/requests.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'server/helpers') 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 @@ import { createWriteStream, remove } from 'fs-extra' -import got, { CancelableRequest, Options as GotOptions } from 'got' +import got, { CancelableRequest, Options as GotOptions, RequestError } from 'got' import { join } from 'path' import { CONFIG } from '../initializers/config' import { ACTIVITY_PUB, PEERTUBE_VERSION, WEBSERVER } from '../initializers/constants' @@ -7,6 +7,11 @@ import { pipelinePromise } from './core-utils' import { processImage } from './image-utils' import { logger } from './logger' +export interface PeerTubeRequestError extends Error { + statusCode?: number + responseBody?: any +} + const httpSignature = require('http-signature') type PeerTubeRequestOptions = { @@ -180,14 +185,15 @@ function buildGotOptions (options: PeerTubeRequestOptions) { } } -function buildRequestError (error: any) { - const newError = new Error(error.message) +function buildRequestError (error: RequestError) { + const newError: PeerTubeRequestError = new Error(error.message) newError.name = error.name newError.stack = error.stack - if (error.response?.body) { - error.responseBody = error.response.body + if (error.response) { + newError.responseBody = error.response.body + newError.statusCode = error.response.statusCode } - return error + return newError } -- cgit v1.2.3