API

Error

Setiap kode error yang dikembalikan API, lengkap dengan status HTTP, pesan, dan cara mengatasinya.

Setiap error punya bentuk yang sama. Periksa error.code di kodemu; pesannya untuk manusia dan bisa berubah.

{
	"error": { "code": "record_changed", "message": "The record changed. Reload it before saving." },
	"meta": { "request_id": "3L3NP3J4G546CPCD6HAIMKRCM6", "response_time": 1 }
}

Detail internal tidak pernah muncul di error. Kirim request_id bersama laporan bug agar bisa dicari di log server. Kolom Pesan menampilkan teks asli dari API, dalam bahasa Inggris.

Error request

StatusCodePesanYang perlu dilakukan
400invalid_inputCheck the submitted values.Perbaiki body, query, atau tipe value. Field wajib harus ada.
400workspace_requiredSend the workspace in the X-Workspace-ID header or use a workspace path.Pakai path dengan :workspace atau kirim X-Workspace-ID.
404not_foundThe requested resource is unavailable.Periksa ID. Kamu juga mendapat ini untuk hal yang tidak boleh kamu lihat.

Error login dan izin

StatusCodePesanYang perlu dilakukan
401authentication_requiredAuthentication is required or credentials are invalid.Kirim satu token yang valid. Login ulang jika sudah kedaluwarsa.
403access_deniedYou do not have permission to perform this action.Minta owner memberi peran dengan akses ini.
403incorrect_passwordThe current password is incorrect.Periksa password saat ini ketika menggantinya.
429rate_limitedToo many requests. Try again later.Tunggu sesuai detik Retry-After, lalu coba lagi.

Error konflik

StatusCodePesanYang perlu dilakukan
409already_existsA conflicting resource or value already exists.Nilai unik sudah dipakai. Gunakan nilai lain.
409ambiguous_lookupThe lookup key matches more than one record.Jadikan field lookup unik.
409schema_changedThe schema changed. Reload it before retrying.Baca ulang koleksi, lalu coba lagi.
409schema_dependencyRemove dependent indexes or lookups before changing field storage.Hapus index atau lookup itu dulu.
409schema_requires_empty_collectionThis schema change requires an empty collection.Kosongkan koleksi atau buat field baru sebagai gantinya.
409index_requires_unique_valuesResolve duplicate values before creating a unique index.Hapus duplikat, lalu tambahkan index.
409workspace_not_emptyThe workspace still contains data. Confirm to delete everything.Konfirmasi penghapusan, atau kosongkan workspace dulu.
412record_changedThe record changed. Reload it before saving.Baca record untuk mendapat ETag baru, lalu coba lagi.
412metadata_changedThe appearance changed. Reload it before saving.Muat ulang pengaturan koleksi, lalu simpan lagi.

Error server

StatusCodePesanYang perlu dilakukan
500internal_errorThe request could not be completed.Coba sekali lagi. Jika berulang, laporkan dengan request_id.
503setup_requiredComplete installation setup before using this service.Klaim instalasi di Studio dulu.
503core_not_initializedThe service is not ready.Tunggu sebentar setelah startup, lalu coba lagi.
503operation_unavailableThis operation is currently unavailable.Fiturnya mati atau tidak didukung di database ini.

Menangani error di kode

const res = await fetch(url, options);
if (!res.ok) {
	const { error, meta } = await res.json();
	if (error.code === 'record_changed') {
		// read the record again and retry
	}
	throw new Error(`${error.code}: ${error.message} (request ${meta.request_id})`);
}
if res.StatusCode >= 400 {
	var out struct {
		Error struct{ Code, Message string } `json:"error"`
		Meta  struct {
			RequestID string `json:"request_id"`
		} `json:"meta"`
	}
	json.NewDecoder(res.Body).Decode(&out)
	return fmt.Errorf("%s: %s (request %s)", out.Error.Code, out.Error.Message, out.Meta.RequestID)
}
if not res.ok:
    body = res.json()
    error, meta = body["error"], body["meta"]
    raise RuntimeError(f"{error['code']}: {error['message']} (request {meta['request_id']})")

Langkah berikutnya

Traktir kopi