Current section

Files

Jump to
scrapbook src scrapbook error.gleam
Raw

src/scrapbook/error.gleam

import gleam/json
/// This type represents the reasons why constructing the HTTP request might fail.
pub type RequestError {
/// Error constructing request from URL.
ConstructionError(url: String)
}
/// This type represents the reasons why the search for the character index in
/// string may fail.
pub type IndexSearchError {
/// Error finding an index with an index of a last analyzed character.
NoIndexFound(last_index: Int)
}
/// This type represents the reasons why a value could not be found.
pub type FindValueError {
/// The key had no assigned value - the value was null.
NoValue
/// There were no graphemes in a list after converting from string.
NoGraphemes
/// Invalid start character of a value - value of the key is not an object or
/// an array.
InvalidStartCharacter
/// Error in finding an index that indicates the end character of a value.
NoValueEndFound(IndexSearchError)
}
/// This type represents the reasons why a key or its value could not be found.
pub type FindKeyValueError {
/// No prefix with the specified key was found. This may mean that the prefix
/// exists in JSON, but its value does not match the required structure and an
/// attempt to find another occurrence of the key failed.
NoPrefix(key: String)
/// Error finding a value.
FindValueError(FindValueError)
}
/// This type represents the reasons why decoding of the JSON failed.
pub type PropertyError {
/// Error in finding the desired key or its value.
FindKeyValueError(FindKeyValueError)
/// Error decoding JSON structure.
DecodeError(json.DecodeError)
/// Error validating decoded data with the passed validator.
ValidateError
}
/// This type represents the reasons why scraping the event might fail.
pub type ScrapeError {
/// Error creating the target URL from the input.
UrlError
/// Error parsing a JSON property from received HTML.
PropertyError(List(PropertyError))
/// Error constructing the HTTP request.
RequestError(RequestError)
}