Skip to content

Commit

Permalink
Not all of the errors return a boxUsage value, so make it optional wh…
Browse files Browse the repository at this point in the history
…en parsing errors.
  • Loading branch information
rbarooah committed Jan 25, 2009
1 parent 8d38509 commit c4416a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/main/scala/org/sublime/amazon/simpleDB/Errors.scala
Expand Up @@ -145,7 +145,10 @@ package org.sublime.amazon.simpleDB {
class URITooLong(code:String, message:String, boxUsage:Double)
extends ClientException(code, message, boxUsage)

def toException(code:String, message:String, boxUsage:Double) = code match {
def toException(code:String, message:String, usage:Option[Double]) =
makeException(code, message, usage getOrElse 0.0)

def makeException(code:String, message:String, boxUsage:Double) = code match {

case "AccessFailure" =>
new AccessFailure(code, message, boxUsage)
Expand Down
9 changes: 7 additions & 2 deletions src/main/scala/org/sublime/amazon/simpleDB/Response.scala
Expand Up @@ -23,7 +23,7 @@ package org.sublime.amazon.simpleDB {

object Error {
/** Extractor so we can pattern match errors **/
def unapply (xml:NodeSeq) :Option[(String, String, Double)] = {
def unapply (xml:NodeSeq) :Option[(String, String, Option[Double])] = {
val element = node("Errors") (xml)
if (element.length > 0) {
val error = (new Errors() (element)).error
Expand All @@ -35,7 +35,7 @@ package org.sublime.amazon.simpleDB {
class Error (implicit xml:NodeSeq) {
val code = string("Code")
val message = string("Message")
val boxUsage = double("BoxUsage")
val boxUsage = optionalDouble("BoxUsage")
}

class SimpleDBResponse (implicit xml:NodeSeq) {
Expand Down Expand Up @@ -210,6 +210,11 @@ package org.sublime.amazon.simpleDB {
def dateField (name:String) (implicit xml:NodeSeq) = dateFormat.parse(string(name))
def int (name:String) (implicit xml:NodeSeq) = Integer.parseInt(string(name))
def double (name:String) (implicit xml:NodeSeq) = java.lang.Double.parseDouble(string(name))
def optionalDouble (name:String) (implicit xml:NodeSeq) :Option[Double] = {
val found = string(name)
if (found.length > 0) Some(java.lang.Double.parseDouble(found))
else None
}
def boolean (name:String) (implicit xml:NodeSeq) = string(name) match {
case "True" => true
case "False" => false
Expand Down

0 comments on commit c4416a9

Please sign in to comment.