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

supabase / storage / 24215850057

09 Apr 2026 10:11PM UTC coverage: 82.434% (+1.6%) from 80.843%
24215850057

Pull #1000

github

web-flow
Merge e13bf9f28 into 41cfe7541
Pull Request #1000: feat: intro vitest & split units

3512 of 7143 branches covered (49.17%)

Branch coverage included in aggregate %.

30 of 31 new or added lines in 2 files covered. (96.77%)

2 existing lines in 1 file now uncovered.

30023 of 33538 relevant lines covered (89.52%)

347.78 hits per line

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

84.97
/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 = (
2✔
14
  app: FastifyInstance,
786✔
15
  options?: {
786✔
16
    respectStatusCode?: boolean
786✔
17
    formatter?: (error: StorageError) => Record<string, any>
786✔
18
  }
786✔
19
) => {
786✔
20
  app.setErrorHandler<Error>(function (error, request, reply) {
793✔
21
    const formatter = options?.formatter || ((e) => e)
240✔
22
    // We assign the error received.
236✔
23
    // it will be logged in the request log plugin
236✔
24
    request.executionError = error
240✔
25

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

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

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

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

176✔
73
      return reply.status(statusCode).send(
180✔
74
        formatter({
176✔
75
          ...renderableError,
176✔
76
          error: error.error || renderableError.code,
176!
77
        })
176✔
78
      )
176✔
79
    }
176✔
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
  })
786✔
115
}
786✔
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