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

supabase / storage / 24133024272

08 Apr 2026 11:29AM UTC coverage: 80.893% (+0.07%) from 80.819%
24133024272

Pull #993

github

web-flow
Merge 62ff99114 into f6e193abb
Pull Request #993: fix: improve sigv4 stream upload performance

3215 of 4195 branches covered (76.64%)

Branch coverage included in aggregate %.

229 of 242 new or added lines in 2 files covered. (94.63%)

3 existing lines in 1 file now uncovered.

30459 of 37433 relevant lines covered (81.37%)

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

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

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

179✔
58
      if (
179✔
59
        renderableError.code === ErrorCode.AbortedTerminate ||
179✔
60
        (error instanceof StorageBackendError && error.shouldCloseConnection())
179✔
61
      ) {
179✔
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

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

60✔
81
    // Fastify errors
60✔
82
    if ('statusCode' in error) {
139✔
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
  })
790✔
115
}
790✔
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