• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / storage / 23865873328

01 Apr 2026 07:04PM UTC coverage: 80.488% (+0.1%) from 80.387%
23865873328

Pull #960

github

web-flow
Merge 01a3c2b1d into 18d938683
Pull Request #960: fix: wrap passthrough proxy for binary

3108 of 4040 branches covered (76.93%)

Branch coverage included in aggregate %.

98 of 103 new or added lines in 4 files covered. (95.15%)

37 existing lines in 2 files now uncovered.

29855 of 36914 relevant lines covered (80.88%)

310.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.48
/src/http/error-handler.ts
1
import { FastifyError } from '@fastify/error'
1✔
2
import { ErrorCode, isRenderableError, StorageError } from '@internal/errors'
1✔
3
import { FastifyInstance } from 'fastify'
1✔
4
import { DatabaseError } from 'pg'
1✔
5

1✔
6
/**
1✔
7
 * The global error handler for all the uncaught exceptions within a request.
1✔
8
 * We try our best to display meaningful information to our users
1✔
9
 * and log any error that occurs
1✔
10
 * @param app
1✔
11
 * @param options
1✔
12
 */
1✔
13
export const setErrorHandler = (
1✔
14
  app: FastifyInstance,
768✔
15
  options?: {
768✔
16
    respectStatusCode?: boolean
768✔
17
    formatter?: (error: StorageError) => Record<string, any>
768✔
18
  }
768✔
19
) => {
768✔
20
  app.setErrorHandler<Error>(function (error, request, reply) {
768✔
21
    const formatter = options?.formatter || ((e) => e)
232✔
22
    // We assign the error received.
232✔
23
    // it will be logged in the request log plugin
232✔
24
    request.executionError = error
232✔
25

232✔
26
    // database error
232✔
27
    if (
232✔
28
      error instanceof DatabaseError &&
232✔
29
      [
1✔
30
        'Authentication error', // supavisor specific
1✔
31
        'Max client connections reached',
1✔
32
        'remaining connection slots are reserved for non-replication superuser connections',
1✔
33
        'no more connections allowed',
1✔
34
        'sorry, too many clients already',
1✔
35
        'server login has been failing, try again later',
1✔
36
      ].some((msg) => (error as DatabaseError).message.includes(msg))
1✔
37
    ) {
232!
38
      return reply.status(429).send(
×
39
        formatter({
×
40
          statusCode: `429`,
×
41
          error: 'too_many_connections',
×
42
          code: ErrorCode.SlowDown,
×
43
          message: 'Too many connections issued to the database',
×
44
        })
×
45
      )
×
46
    }
×
47

232✔
48
    if (isRenderableError(error)) {
232✔
49
      const renderableError = error.render()
173✔
50
      const statusCode = options?.respectStatusCode
173✔
51
        ? parseInt(renderableError.statusCode, 10)
173✔
52
        : error.userStatusCode
173✔
53
          ? error.userStatusCode
148✔
54
          : renderableError.statusCode === '500'
148!
55
            ? 500
×
56
            : 400
×
57

173✔
58
      if (renderableError.code === ErrorCode.AbortedTerminate) {
173!
NEW
59
        reply.header('Connection', 'close')
×
NEW
60

×
NEW
61
        reply.raw.once('finish', () => {
×
62
          setTimeout(() => {
×
63
            if (!request.raw.closed) {
×
64
              request.raw.destroy()
×
65
            }
×
66
          }, 3000)
×
67
        })
×
68
      }
×
69

173✔
70
      return reply.status(statusCode).send(
173✔
71
        formatter({
173✔
72
          ...renderableError,
173✔
73
          error: error.error || renderableError.code,
173✔
74
        })
173✔
75
      )
173✔
76
    }
173✔
77

59✔
78
    // Fastify errors
59✔
79
    if ('statusCode' in error) {
137✔
80
      const err = error as FastifyError
56✔
81

56✔
82
      if (err.code === 'FST_ERR_CTP_INVALID_MEDIA_TYPE') {
56✔
83
        return reply.status(400).send(
3✔
84
          formatter({
3✔
85
            statusCode: '415',
3✔
86
            code: ErrorCode.InvalidMimeType,
3✔
87
            error: 'invalid_mime_type',
3✔
88
            message: 'Invalid Content-Type header',
3✔
89
          })
3✔
90
        )
3✔
91
      }
3✔
92

53✔
93
      return reply.status(err.statusCode || 500).send(
56!
94
        formatter({
56✔
95
          statusCode: `${err.statusCode}`,
56✔
96
          error: err.name,
56✔
97
          code: ErrorCode.InternalError,
56✔
98
          message: err.message,
56✔
99
        })
56✔
100
      )
56✔
101
    }
56✔
102

3✔
103
    return reply.status(500).send(
3✔
104
      formatter({
3✔
105
        statusCode: '500',
3✔
106
        error: 'Internal',
3✔
107
        message: 'Internal Server Error',
3✔
108
        code: ErrorCode.InternalError,
3✔
109
      })
3✔
110
    )
3✔
111
  })
768✔
112
}
768✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc