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

supabase / storage / 16223502981

11 Jul 2025 03:16PM UTC coverage: 77.08% (-0.9%) from 77.981%
16223502981

push

github

web-flow
fix: analytic bucket support

1623 of 2339 branches covered (69.39%)

Branch coverage included in aggregate %.

3010 of 3976 new or added lines in 64 files covered. (75.7%)

84 existing lines in 10 files now uncovered.

20321 of 26130 relevant lines covered (77.77%)

102.97 hits per line

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

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

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

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

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

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

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

15✔
78
    // Fastify errors
15✔
79
    if ('statusCode' in error) {
15✔
80
      const err = error as FastifyError
15✔
81
      return reply.status(err.statusCode || 500).send(
15!
82
        formatter({
15✔
83
          statusCode: `${err.statusCode}`,
15✔
84
          error: err.name,
15✔
85
          code: ErrorCode.InternalError,
15✔
86
          message: err.message,
15✔
87
        })
15✔
88
      )
15✔
89
    }
15✔
90

×
NEW
91
    return reply.status(500).send(
×
NEW
92
      formatter({
×
NEW
93
        statusCode: '500',
×
NEW
94
        error: 'Internal',
×
NEW
95
        message: 'Internal Server Error',
×
NEW
96
        code: ErrorCode.InternalError,
×
NEW
97
      })
×
NEW
98
    )
×
99
  })
245✔
100
}
245✔
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