]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Tests: Add response error along with unexpected status in report
authorFlorent <florent.git@zeteo.me>
Thu, 11 Aug 2022 15:24:23 +0000 (17:24 +0200)
committerChocobozzz <chocobozzz@cpy.re>
Tue, 16 Aug 2022 08:00:04 +0000 (10:00 +0200)
shared/server-commands/requests/requests.ts

index a08a6e0b9b5b7fe3a7ab070b203fd7eeadedb42e..85cbc9be939f807df0dc229253e08b4220fa7551 100644 (file)
@@ -172,7 +172,6 @@ function buildRequest (req: request.Test, options: CommonRequestParams) {
   if (options.accept) req.set('Accept', options.accept)
   if (options.host) req.set('Host', options.host)
   if (options.redirects) req.redirects(options.redirects)
-  if (options.expectedStatus) req.expect(options.expectedStatus)
   if (options.xForwardedFor) req.set('X-Forwarded-For', options.xForwardedFor)
   if (options.type) req.type(options.type)
 
@@ -180,7 +179,15 @@ function buildRequest (req: request.Test, options: CommonRequestParams) {
     req.set(name, options.headers[name])
   })
 
-  return req
+  return req.expect((res) => {
+    if (options.expectedStatus && res.status !== options.expectedStatus) {
+      throw new Error(`Expected status ${options.expectedStatus}, got ${res.status}. ` +
+        `\nThe server responded this error: "${res.body?.error ?? res.text}".\n` +
+        'You may take a closer look at the logs. To see how to do so, check out this page: ' +
+        'https://github.com/Chocobozzz/PeerTube/blob/develop/support/doc/development/tests.md#debug-server-logs')
+    }
+    return res
+  })
 }
 
 function buildFields (req: request.Test, fields: { [ fieldName: string ]: any }, namespace?: string) {