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

supabase / storage / 26155689234

20 May 2026 10:06AM UTC coverage: 57.697% (-17.2%) from 74.874%
26155689234

Pull #1115

github

web-flow
Merge d6a84934b into 9a13d3ea2
Pull Request #1115: Encapsulate storage database transaction APIs

2784 of 5519 branches covered (50.44%)

Branch coverage included in aggregate %.

122 of 145 new or added lines in 7 files covered. (84.14%)

1665 existing lines in 69 files now uncovered.

5938 of 9598 relevant lines covered (61.87%)

407.09 hits per line

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

71.43
/src/http/error-handler.ts
1
import { FastifyError } from '@fastify/error'
2
import { ErrorCode, isRenderableError, StorageBackendError, StorageError } from '@internal/errors'
3
import { isDatabaseSlowDownError } from '@internal/errors/database-error'
4
import { FastifyInstance } from 'fastify'
5

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

26
    // database error
27
    if (isDatabaseSlowDownError(error)) {
245!
28
      return reply.status(429).send(
×
29
        formatter({
30
          statusCode: `429`,
31
          error: 'too_many_connections',
32
          code: ErrorCode.SlowDown,
33
          message: 'Too many connections issued to the database',
34
        })
35
      )
36
    }
37

38
    if (isRenderableError(error)) {
245✔
39
      const renderableError = error.render()
183✔
40
      const statusCode = options?.respectStatusCode
183✔
41
        ? parseInt(renderableError.statusCode, 10)
42
        : error.userStatusCode
156!
43
          ? error.userStatusCode
44
          : renderableError.statusCode === '500'
×
45
            ? 500
46
            : 400
47

48
      if (
183!
49
        renderableError.code === ErrorCode.AbortedTerminate ||
549✔
50
        (error instanceof StorageBackendError && error.shouldCloseConnection())
51
      ) {
UNCOV
52
        reply.header('Connection', 'close')
×
53

UNCOV
54
        reply.raw.once('finish', () => {
×
UNCOV
55
          setTimeout(() => {
×
56
            if (!request.raw.closed) {
×
57
              request.raw.destroy()
×
58
            }
59
          }, 3000)
60
        })
61
      }
62

63
      return reply.status(statusCode).send(
183✔
64
        formatter({
65
          ...renderableError,
66
          error: error.error || renderableError.code,
215✔
67
        })
68
      )
69
    }
70

71
    // Fastify errors
72
    if ('statusCode' in error) {
62✔
73
      const err = error as FastifyError
58✔
74

75
      if (err.code === 'FST_ERR_CTP_INVALID_MEDIA_TYPE') {
58✔
76
        return reply.status(400).send(
3✔
77
          formatter({
78
            statusCode: '415',
79
            code: ErrorCode.InvalidMimeType,
80
            error: 'invalid_mime_type',
81
            message: 'Invalid Content-Type header',
82
          })
83
        )
84
      }
85

86
      return reply.status(err.statusCode || 500).send(
55!
87
        formatter({
88
          statusCode: `${err.statusCode}`,
89
          error: err.name,
90
          code: ErrorCode.InternalError,
91
          message: err.message,
92
        })
93
      )
94
    }
95

96
    return reply.status(500).send(
4✔
97
      formatter({
98
        statusCode: '500',
99
        error: 'Internal',
100
        message: 'Internal Server Error',
101
        code: ErrorCode.InternalError,
102
      })
103
    )
104
  })
105
}
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