parsehttp

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 4 Imported by: 0

README

parse/parsehttp

Writes parse's request errors as HTTP responses for servers without an error envelope of their own: the status the error's code declares and a JSON body of code, message and details.

Quick Start

func (s *server) fail(w http.ResponseWriter, r *http.Request, err error) {
	if parsehttp.WriteError(w, err) {
		return
	}
	s.log.ErrorContext(r.Context(), "request failed", slog.Any("error", err))
	http.Error(w, "internal error", http.StatusInternalServerError)
}

API Reference

  • WriteError(w http.ResponseWriter, err error) bool — answers err when a *core.ParseError is in its chain, with ParseError.ErrorHTTPStatus() and Body; reports whether it did. Any other error is the caller's.
  • Body — {"code", "message", "details"}, the shape the TypeScript SDK reads.

A parse error describes the request, never the database, so its message is safe to return; everything else is left to the caller to log and answer without internals.

Key Files

File Responsibility
parsehttp.go WriteError, Body
parsehttp_test.go Status and body of a wrapped parse error; other errors left alone

Dependencies

  • Imports: parse/core, standard library
  • Imported by: parse/examples/server
  • Package boundary: standalone Parse module

References

Documentation

Overview

Package parsehttp writes parse's request errors as HTTP responses , for servers that do not have an error envelope of their own.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteError

func WriteError(w http.ResponseWriter, err error) bool

WriteError answers err when it is a parse error — anywhere in its chain — with the status its code declares and Body, and reports whether it did. Any other error is the caller's to answer.

Types

type Body

type Body struct {
	Code    string         `json:"code"`
	Message string         `json:"message"`
	Details map[string]any `json:"details,omitempty"`
}

Body is the JSON a parse error is answered with.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL