-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add test * Add details * fix code style * update version and bundle, and fix vulnerability * more platforms * fix dependencies with ruby 2.6.10 * just return all details * handle all errors * update version
- Loading branch information
Showing
5 changed files
with
114 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require "json" | ||
|
||
module Veryfi | ||
class Error | ||
def self.from_response(status, response) | ||
if response.empty? | ||
VeryfiError.new(format("%<code>d", code: status)) | ||
else | ||
get_error(status, response) | ||
end | ||
end | ||
|
||
def self.get_error(status, response) | ||
case status | ||
when 400 then BadRequest | ||
when 401 then UnauthorizedAccessToken | ||
when 404 then ResourceNotFound | ||
when 405 then UnexpectedHTTPMethod | ||
when 409 then AccessLimitReached | ||
when 500 then InternalError | ||
else VeryfiError.new(format("%<code>d, %<message>s", code: status, message: response["error"])) | ||
end | ||
end | ||
class BadRequest < VeryfiError | ||
def to_s | ||
"400, Bad Request" | ||
end | ||
end | ||
|
||
class UnauthorizedAccessToken < VeryfiError | ||
def to_s | ||
"401, Unauthorized Access Token" | ||
end | ||
end | ||
|
||
class ResourceNotFound < VeryfiError | ||
def to_s | ||
"404, Resource not found" | ||
VeryfiError.new(format("%<code>d, %<message>s", code: status, message: response["error"]), response) | ||
end | ||
end | ||
|
||
class UnexpectedHTTPMethod < VeryfiError | ||
def to_s | ||
"405, Unexpected HTTP Method" | ||
end | ||
end | ||
class VeryfiError < StandardError | ||
attr_reader :message | ||
|
||
class AccessLimitReached < VeryfiError | ||
def to_s | ||
"409, Access Limit Reached" | ||
def initialize(message = "An error occurred", response = {}) | ||
@message = if response.empty? | ||
message | ||
else | ||
JSON.pretty_generate(response) | ||
end | ||
super(message) | ||
end | ||
end | ||
|
||
class InternalError < VeryfiError | ||
def to_s | ||
"500, Internal Server Error" | ||
message | ||
end | ||
end | ||
|
||
class VeryfiError < StandardError | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module Veryfi | ||
VERSION = "1.0.4" | ||
VERSION = "2.0.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters