mirror of
https://github.com/supabase/supabase.git
synced 2026-05-07 01:10:15 -04:00
aba0095bd7
* feat(content api): add error endpoint
Add an endpoint to return the details of a Supabase error, given the
error code and service.
Schema additions:
```graphql
type RootQueryType {
"...previous root queries"
"""Get the details of an error code returned from a Supabase service"""
error(code: String!, service: Service!): Error
}
"""An error returned by a Supabase service"""
type Error {
"""
The unique code identifying the error. The code is stable, and can be used for string matching during error handling.
"""
code: String!
"""The Supabase service that returns this error."""
service: Service!
"""The HTTP status code returned with this error."""
httpStatusCode: Int
"""
A human-readable message describing the error. The message is not stable, and should not be used for string matching during error handling. Use the code instead.
"""
message: String
}
enum Service {
AUTH
REALTIME
STORAGE
}
```
* test(content api): add tests for top-level query `error`
65 lines
1.6 KiB
TypeScript
65 lines
1.6 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
import { POST } from '../route'
|
|
|
|
describe('/api/graphql error', () => {
|
|
it('returns the error matching given error code and service', async () => {
|
|
const errorQuery = `
|
|
query {
|
|
error(code: "test_code", service: AUTH) {
|
|
code
|
|
service
|
|
httpStatusCode
|
|
message
|
|
}
|
|
}
|
|
`
|
|
const request = new Request('http://localhost/api/graphql', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ query: errorQuery }),
|
|
})
|
|
|
|
const result = await POST(request)
|
|
const {
|
|
data: { error },
|
|
errors,
|
|
} = await result.json()
|
|
|
|
expect(errors).toBeUndefined()
|
|
expect(error.code).toBe('test_code')
|
|
expect(error.service).toBe('AUTH')
|
|
expect(error.httpStatusCode).toBe(500)
|
|
expect(error.message).toBe('This is a test error message')
|
|
})
|
|
|
|
it('returns error if no matching error exists', async () => {
|
|
vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
|
|
const errorQuery = `
|
|
query {
|
|
error(code: "nonexistent_code", service: AUTH) {
|
|
code
|
|
service
|
|
httpStatusCode
|
|
message
|
|
}
|
|
}
|
|
`
|
|
const request = new Request('http://localhost/api/graphql', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ query: errorQuery }),
|
|
})
|
|
|
|
const result = await POST(request)
|
|
const {
|
|
data: { error },
|
|
errors,
|
|
} = await result.json()
|
|
|
|
expect(error).toBe(null)
|
|
expect(errors).toHaveLength(1)
|
|
expect(errors[0].message).toMatch(/not found/i)
|
|
|
|
vi.restoreAllMocks()
|
|
})
|
|
})
|