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

supabase / storage / 24239132798

10 Apr 2026 10:43AM UTC coverage: 80.843%. Remained the same
24239132798

push

github

web-flow
feat: add hit ratio tenant pool cache (#1002)

3167 of 4137 branches covered (76.55%)

Branch coverage included in aggregate %.

22 of 22 new or added lines in 2 files covered. (100.0%)

3 existing lines in 1 file now uncovered.

30285 of 37242 relevant lines covered (81.32%)

320.42 hits per line

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

87.86
/src/http/error-handler.ts
1
import { FastifyError } from '@fastify/error'
1✔
2
import { ErrorCode, isRenderableError, StorageBackendError, 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,
793✔
15
  options?: {
793✔
16
    respectStatusCode?: boolean
793✔
17
    formatter?: (error: StorageError) => Record<string, any>
793✔
18
  }
793✔
19
) => {
793✔
20
  app.setErrorHandler<Error>(function (error, request, reply) {
793✔
21
    const formatter = options?.formatter || ((e) => e)
240✔
22
    // We assign the error received.
240✔
23
    // it will be logged in the request log plugin
240✔
24
    request.executionError = error
240✔
25

240✔
26
    // database error
240✔
27
    if (
240✔
28
      error instanceof DatabaseError &&
240✔
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
    ) {
240!
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

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

180✔
58
      if (
180✔
59
        renderableError.code === ErrorCode.AbortedTerminate ||
180✔
60
        (error instanceof StorageBackendError && error.shouldCloseConnection())
180✔
61
      ) {
180✔
62
        reply.header('Connection', 'close')
1✔
63

1✔
64
        reply.raw.once('finish', () => {
1✔
65
          setTimeout(() => {
1✔
UNCOV
66
            if (!request.raw.closed) {
×
UNCOV
67
              request.raw.destroy()
×
UNCOV
68
            }
×
69
          }, 3000)
1✔
70
        })
1✔
71
      }
1✔
72

180✔
73
      return reply.status(statusCode).send(
180✔
74
        formatter({
180✔
75
          ...renderableError,
180✔
76
          error: error.error || renderableError.code,
180✔
77
        })
180✔
78
      )
180✔
79
    }
180✔
80

60✔
81
    // Fastify errors
60✔
82
    if ('statusCode' in error) {
140✔
83
      const err = error as FastifyError
56✔
84

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

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

4✔
106
    return reply.status(500).send(
4✔
107
      formatter({
4✔
108
        statusCode: '500',
4✔
109
        error: 'Internal',
4✔
110
        message: 'Internal Server Error',
4✔
111
        code: ErrorCode.InternalError,
4✔
112
      })
4✔
113
    )
4✔
114
  })
793✔
115
}
793✔
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