Sha256: fc437161ffe2489f976b7b41927ac4a20ecbb6c7d8f9ade4d0c1c2e25fee0a25
Contents?: true
Size: 1.47 KB
Versions: 3
Compression:
Stored size: 1.47 KB
Contents
# Sourced from notion-sdk-js: # https://github.com/makenotion/notion-sdk-js/blob/main/src/errors.ts module Notion API_ERROR_CODE = { unauthorized: "unauthorized", restricted_resource: "restricted_resource", object_not_found: "object_not_found", rate_limited: "rate_limited", invalid_json: "invalid_json", invalid_request_url: "invalid_request_url", invalid_request: "invalid_request", validation_error: "validation_error", conflict_error: "conflict_error", internal_server_error: "internal_server_error", service_unavailable: "service_unavailable" } class ErrorFactory def self.create(error = {}) return NotionError.new("Unknown error.") if error["message"].nil? if API_ERROR_CODE.value?(error["code"]) APIResponseError.new(error["message"], body: error) elsif error["request"] && error["response"] && error["timings"] HTTPResponseError.new(error["message"], body: error) elsif error["request"] && error["timings"] RequestTimeoutError.new(error["message"], body: error) else NotionError.new(error["message"]) end end end class NotionError < StandardError attr_reader :message, :body def initialize(message = nil, body: nil) @message = message @body = body end end class RequestTimeoutError < NotionError; end class HTTPResponseError < NotionError; end class APIResponseError < NotionError def code body["code"] end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
notion-sdk-ruby-0.6.1 | lib/notion-sdk-ruby/error.rb |
notion-sdk-ruby-0.6.0 | lib/notion-sdk-ruby/error.rb |
notion-sdk-ruby-0.4.0 | lib/notion-sdk-ruby/error.rb |